套接字帮忙 [英] socket help urgent

查看:73
本文介绍了套接字帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello
我正在开发Asyncronous套接字编程"UDP"在回调方法中,我想知道哪个Ip发送给我的消息..请参阅下面的代码

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)
{
_Objsoc k1234.BeginReceiveFrom(data,0,data.Length,0,ref rep,
new AsyncCallback(ReceiveCallback),_ Objsock1234);
}


}
} < br> catch(Exception ex)
{
throw ex;
}


这是我

解决方案

< BLOCKQUOTE> http://www.devarticles.com/c/a/C-Sharp/Socket-Programming-in-C-sharp-Part-II/1/

Hello
           I am working on Asyncronous socket programing "UDP" In the call back method i want to know which Ip has send me the message .. see the code below

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;
            }


It's Me

解决方案

http://www.devarticles.com/c/a/C-Sharp/Socket-Programming-in-C-sharp-Part-II/1/


这篇关于套接字帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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