且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UDP同时通过两个应用程序在同一端口上进行侦听

更新时间:2023-11-22 20:34:10

U?ytkownik" mBird" < no@spam.com> napisa3 w wiadomo?ci

新闻:Ez ********************* @ twister.nyroc.rr.com。 ..
U?ytkownik "mBird" <no@spam.com> napisa3 w wiadomo?ci
news:Ez*********************@twister.nyroc.rr.com. ..
我编写了一个服务,用于侦听来自我的防火墙
(UDP snmp陷阱消息)的广播消息,并将数据解析并放入数据库中。

我还想编写一个简单的应用程序,它可以在运行时收听
(因此我可以在表单中看到消息。)

所以我需要能够在相同的
时间(服务和我的应用程序)使用两个应用程序收听UDP端口。但是当我这样做时,我收到一个错误:
System.Net.Sockets.SocketException:系统通常只允许使用每个套接字地址
(协议/网络地址/端口)
.Net.Sockets.Socket.Bind(EndPoint localEP)
在UdpReceive.Class1.StartReceiveFrom()中的c:\ myprojects \ _dotnet \cs \ network
>是否可以同时使用两个应用程序收听同一个端口?

谢谢

ps我可以这样做的一种方法是使用数据包驱动程序和类似的WinPCap,只需从我拥有的任何应用程序中抓取帧 - 但我想要
严格地尝试使用DotNet Framework和C#。
I wrote a service that listens for broadcast messages from my firewall (UDP snmp trap messages) and parses and puts the data in an database.

I''d also like to write an app that is a simple form that can listen in when it runs (so I can see messages in a form as they occur.)

So I need the ability to listen to a UDP port with two apps at the same time (the service and my app). But when I do that I get an error:
System.Net.Sockets.SocketException: Only one usage of each socket address
(protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at UdpReceive.Class1.StartReceiveFrom() in
c:\myprojects\dotnet\cs\networking

Is it possible to listen to the same port with two apps at once?

Thank you

p.s. One way I could do this is to use a packet driver and something like
WinPCap and just grab the frames from any app I have -- but I''d like to try this strictly from the DotNet Framework and C#.



我想你不能(或许你不应该)。这与UDP

标准不兼容。


I think you can''t (Or maybe you shouldn''t). It''s incompatible with UDP
standard.





" mBird" &LT; no@spam.com>在消息中写道

新闻:Ez ********************* @ twister.nyroc.rr.com。 ..
Hi,

"mBird" <no@spam.com> wrote in message
news:Ez*********************@twister.nyroc.rr.com. ..
我编写了一个服务,用于侦听来自我的防火墙
(UDP snmp陷阱消息)的广播消息,并将数据解析并放入数据库中。

我还想编写一个简单的应用程序,它可以在运行时收听
(因此我可以在表单中看到消息。)

所以我需要能够在相同的
时间(服务和我的应用程序)使用两个应用程序收听UDP端口。但是当我这样做时,我收到一个错误:
System.Net.Sockets.SocketException:系统通常只允许使用每个套接字地址
(协议/网络地址/端口)
.Net.Sockets.Socket.Bind(EndPoint localEP)
在UdpReceive.Class1.StartReceiveFrom()中的c:\ myprojects \ _dotnet \cs \ network
>是否可以同时使用两个应用程序收听同一个端口?


在调用bind之前尝试设置以下选项:

_socket.SetSocketOption(SocketOptionLevel.Socket,

SocketOptionName.ReuseAddress, 1);

HTH,

问候


谢谢

ps我可以这样做的一种方法是使用数据包驱动程序和类似的WinPCap,只需从我拥有的任何应用程序中抓取帧 - 但我想要
严格地尝试使用DotNet Framework和C#。
I wrote a service that listens for broadcast messages from my firewall (UDP snmp trap messages) and parses and puts the data in an database.

I''d also like to write an app that is a simple form that can listen in when it runs (so I can see messages in a form as they occur.)

So I need the ability to listen to a UDP port with two apps at the same time (the service and my app). But when I do that I get an error:
System.Net.Sockets.SocketException: Only one usage of each socket address
(protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at UdpReceive.Class1.StartReceiveFrom() in
c:\myprojects\dotnet\cs\networking

Is it possible to listen to the same port with two apps at once?
Try to set the following option before calling bind :
_socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress, 1);
HTH,
greetings


Thank you

p.s. One way I could do this is to use a packet driver and something like
WinPCap and just grab the frames from any app I have -- but I''d like to try this strictly from the DotNet Framework and C#.



" mBird" &LT; no@spam.com>在消息新闻中写道:Ez ********************* @ twister.nyroc.rr.com。 ..


我原以为***的方法就是让服务向你的表单发送消息。


-

Michael Culley
"mBird" <no@spam.com> wrote in message news:Ez*********************@twister.nyroc.rr.com. ..

I would have thought the best method would be to have the service send a message to your form.

--
Michael Culley