UDP同时通过两个应用程序在同一端口上进行侦听 [英] UDP Listen on same port by two apps at same time

查看:508
本文介绍了UDP同时通过两个应用程序在同一端口上进行侦听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个服务,用于侦听来自我的防火墙的广播消息(UDP

snmp陷阱消息)并解析并将数据放入数据库中。


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


所以我需要能够同时收听两个应用程序的UDP端口

(该服务和我的应用程序)。但当我这样做时,我收到一个错误:

System.Net.Sockets.SocketException:每个套接字地址只有一种用法

(协议/网络地址/端口)是通常允许

在System.Net.Sockets.Socket.Bind(EndPoint localEP)

at UdpReceive.Class1.StartReceiveFrom()in

c: \ myprojects\dotnet\cs\\\
etworking


是否可以同时使用两个应用程序收听同一个端口?


谢谢


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#.

推荐答案

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" < 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" < 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


这篇关于UDP同时通过两个应用程序在同一端口上进行侦听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆