socket UDP问题 [英] socket UDP issue
问题描述
你好
我正在听udp并在修改数据之后。我想知道我从哪个IP地址获取数据。和m_SocketAddress给我这个,但这是非公开成员
public static void ReceiveCallback(IAsyncResult iar )
{
在这里我想知道哪个服务器向我发送了消息
AsyncState;
IPEndPoint sender = new IPEndPoint(IPAddress.Any,1234);
EndPoint rep =(EndPoint)sender;
int read = remort.EndReceiveFrom(iar,ref rep);
if(读> 0)
{
_Objsock1234.BeginReceive From(data,0,data.Length,0,ref rep,
new AsyncCallback(ReceiveCallback),_ Objsock1234);
}
Hello
I am listen a udp and after revicing the data. I want to know from which ip address I have recive data. and m_SocketAddress give me this but this is non public member
public static void ReceiveCallback(IAsyncResult iar)
{
Here I want to know which server has send me the message
try
{
lock (_lock)
{
Socket remort = (Socket)iar.AsyncState;
IPEndPoint sender = new IPEndPoint(IPAddress.Any , 1234);
EndPoint rep = (EndPoint)sender;
int read = remort.EndReceiveFrom(iar, ref rep);
if (read > 0)
{
_Objsock1234.BeginReceiveFrom(data, 0, data.Length, 0, ref rep,
new AsyncCallback(ReceiveCallback), _Objsock1234);
}
}
catch(Exception ex)
{
throw ex;
}
}
}
catch (Exception ex)
{
throw ex;
}
推荐答案
这是调用EndReceiveFrom后存储在rep中的内容。 :-)至少我是这样理解的。
That's what is stored in rep after calling EndReceiveFrom. :-) At least that's how I understand it.
这篇关于socket UDP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!