听港口 [英] Listen to Port
本文介绍了听港口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找侦听tcp端口的代码。另一个(不是.net)进程
将在同一台计算机上写入该端口,我需要c#代码才能获得数据,这是一个简单的字符串,从那个港口。我不是#
编码器,但可以很容易地调整工作样本。
非常感谢你的帮助。
I am looking for code to listen to a tcp port. Another (not .net) process
will be writing to that port on the same computer and I need c# code to be
able to get data, which is a simple string, from that port. I am not a c#
coder but can easy adapt working sample.
Thanks alot for help.
推荐答案
阅读创建套接字监听器
http://www.devarticles.com/c/a/C-Sha...g-in-C-Part-I/
问候
John Timney(MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
" markgoldin" < ma ************* @ yahoo.comwrote in message
news:03 ***************** ***************** @ microsof t.com ...
read up on creating a socket listener
http://www.devarticles.com/c/a/C-Sha...g-in-C-Part-I/
Regards
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"markgoldin" <ma*************@yahoo.comwrote in message
news:03**********************************@microsof t.com...
>我正在寻找聆听的代码到一个TCP端口。另一个(不是.net)进程将在同一台计算机上写入该端口,我需要c#代码才能从该端口获取数据,这是一个简单的字符串。我不是一个c#
编码器,但可以很容易地调整工作样本。
非常感谢你的帮助。
>I am looking for code to listen to a tcp port. Another (not .net) process
will be writing to that port on the same computer and I need c# code to be
able to get data, which is a simple string, from that port. I am not a c#
coder but can easy adapt working sample.
Thanks alot for help.
这在.NET中很容易实现。这就是你所需要的:
//在控制台内部主要
byte [] byteReadStream = null; //将数据保存在字节缓冲区中
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(" 0.0.0.0"),
8888); //收听所有本地地址和8888端口
TcpListener tcpl = new TcpListener(ipe);
while(true){//无限循环
tcpl.Start(); //阻止应用程序直到数据和连接
请求
TcpClient tcpc = tcpl.AcceptTcpClient(); //接受连接
byteReadStream = new byte [tcpc.Available]; //为数据分配空间
tcpc.GetStream()。读取(byteReadStream,0,tcpc.Available);
//读取数据到字节数组
Console.WriteLine(Encoding.Default.GetString(byteR eadStream)
+" \ n");将数据写入控制台缓冲区
}
但请参阅MSDN Library以获取更多信息
关于使用的类。
问候
Kerem
-
-
--- --------------------
BesteGrüsse/致敬/ Votre bien devoue
KeremGümrükcü>
Microsoft Live Space: http://kerem-g.spaces。 live.com/
最新的开源项目: http: //entwicklung.junetz.de
-----------------------
此回复按原样提供,不附带任何明示或暗示的保证。
" markgoldin" < ma ************* @ yahoo.comschrieb im Newsbeitrag
news:03 ***************** ***************** @ microsof t.com ...
Hi,
thats really easy to do in .NET. Thats all you need:
//inside a console Main
byte[] byteReadStream = null; // holds the data in byte buffer
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("0.0.0.0"),
8888);//listen on all local addresses and 8888 port
TcpListener tcpl = new TcpListener(ipe);
while(true){ //infinite loop
tcpl.Start(); // block application until data and connection
is requested
TcpClient tcpc = tcpl.AcceptTcpClient(); //accept connection
byteReadStream = new byte[tcpc.Available]; //allocate space
for data
tcpc.GetStream().Read(byteReadStream, 0, tcpc.Available);
//read data into byte array
Console.WriteLine(Encoding.Default.GetString(byteR eadStream)
+ "\n"); Write data to console buffer
}
But see the MSDN Library for more information
about the used Classes.
Regards
Kerem
--
--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
"markgoldin" <ma*************@yahoo.comschrieb im Newsbeitrag
news:03**********************************@microsof t.com...
我正在寻找能够收听的代码tcp端口。另一个(不是.net)进程
将在同一台计算机上写入该端口,我需要c#代码到
I am looking for code to listen to a tcp port. Another (not .net) process
will be writing to that port on the same computer and I need c# code to
是
be
能够从该端口获取数据,这是一个简单的字符串。我不是#
编码器,但可以很容易地调整工作样本。
非常感谢你的帮助。
able to get data, which is a simple string, from that port. I am not a c#
coder but can easy adapt working sample.
Thanks alot for help.
监听套接字或TCP端口有什么区别?或者它是
相同?
谢谢
" John Timney(MVP)" < xy ****** @ timney.eclipse.co.ukwrote in message
新闻:Qd ******************** **********@eclipse.net。 uk ...
What is a difference between listening to a socket or to a TCP port? Or it''s
the same?
Thanks
"John Timney (MVP)" <xy******@timney.eclipse.co.ukwrote in message
news:Qd******************************@eclipse.net. uk...
读取创建套接字监听器
http://www.devarticles.com/c/a/C-Sha...g- in-C-Part-I
问候
John Timney(MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
" markgoldin" < ma ************* @ yahoo.comwrote in message
news:03 ***************** ***************** @ microsof t.com ...
read up on creating a socket listener
http://www.devarticles.com/c/a/C-Sha...g-in-C-Part-I/
Regards
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"markgoldin" <ma*************@yahoo.comwrote in message
news:03**********************************@microsof t.com...
>>我正在寻找代码听tcp端口。另一个(不是.net)进程将在同一台计算机上写入该端口,我需要c#代码才能从该端口获取数据,这是一个简单的字符串。我不是一个c#编码器,但可以很容易地调整工作样本。
非常感谢你的帮助。
>>I am looking for code to listen to a tcp port. Another (not .net) process
will be writing to that port on the same computer and I need c# code to
be able to get data, which is a simple string, from that port. I am not a
c# coder but can easy adapt working sample.
Thanks alot for help.
这篇关于听港口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文