Windows phone 8 Netframework v4 socket中的BeginRead方法等效于什么
在netframework v2中,套接字使用Invoke(beginhead)方法调用方法(示例ReceiveMsg),如下所示: client=新的TcpClient()Windows phone 8 Netframework v4 socket中的BeginRead方法等效于什么,windows-phone-8,Windows Phone 8,在netframework v2中,套接字使用Invoke(beginhead)方法调用方法(示例ReceiveMsg),如下所示: client=新的TcpClient() client.Connect(SERVERIP,端口号) 数据=新字节[client.ReceiveBufferSize] SendMessage(“hello\n”) client.GetStream().BeginRead(数据,0,System.Convert.ToInt32(client.ReceiveBuffer
client.Connect(SERVERIP,端口号)
数据=新字节[client.ReceiveBufferSize]
SendMessage(“hello\n”) client.GetStream().BeginRead(数据,0,System.Convert.ToInt32(client.ReceiveBufferSize),ReceiveMsg,null)
为什么你需要这个(尤其是当你似乎不明白你在试图做什么的时候)?您已经从MSDN获得了.NET4的工作示例…@Paul Annetts:谢谢。根据链接,我遵循了.Net4示例。我似乎无法像.NETV2那样,按照我想要的GetStream方法,以连续循环的方式获取接收消息。非常感谢你在这件事上的帮助。 public string Receive() { //-- receive the reply from server string response = "Receiving Operation Timeout"; // We are receiving over an established socket connection if (_socket != null) { // Create SocketAsyncEventArgs context object SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint; // Setup the buffer to receive the data socketEventArg.SetBuffer(new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE); // Inline event handler for the Completed event. // Note: This even handler was implemented inline in order to make this method self-contained. socketEventArg.Completed += new EventHandler(delegate(object s, SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success) { // Retrieve the data from the buffer response = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred); response = response.Trim('\0'); } else { response = e.SocketError.ToString(); } _clientDone.Set(); }); // Sets the state of the event to nonsignaled, causing threads to block _clientDone.Reset(); // Make an asynchronous Receive request over the socket _socket.ReceiveAsync(socketEventArg); // Block the UI thread for a maximum of TIMEOUT_MILLISECONDS seconds. // If no response comes back within this time then proceed _clientDone.WaitOne(TIMEOUT_MILLISECONDS); } else { response = "Socket is not initialized"; } return response; }