C# Socket异步通讯客户端之发送数据
C# Socket异步通讯客户端之主程序:
[c-sharp] 
view plaincopyprint?
 
- # public static int Main(String[] args)    
 - # {    
 - #    
 - # IPAddress ipAddress = IPAddress.Parse("192.168.1.104");    
 - # int port = 20000;    
 - # IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);    
 - #    
 - # // 生成一个TCP/IP socket.    
 - # Socket client = new Socket(AddressFamily.InterNetwork,    
 - # SocketType.Stream, ProtocolType.Tcp);    
 - #    
 - # // 与目标终端连接.    
 - # client.BeginConnect(remoteEP,    
 - # new AsyncCallback(ConnectCallback), client);    
 - # //等待,直到连接程序完成。在ConnectCallback中适当位置有connecDone.Set()语句    
 - # connectDone.WaitOne();    
 - #    
 - # // 发送数据到远程终端.    
 - # Send(client, "This is a test<EOF>");    
 - # sendDone.WaitOne();    
 - #    
 - # // 接收返回数据.    
 - # Receive(client);    
 - # receiveDone.WaitOne();    
 - #    
 - # // Write the response to the console.    
 - # Console.WriteLine("Response received : {0}", response);    
 - #  
                        
                    
 
 
                    
                    
                        免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。