Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving messages through a socket
    text
    copied!<p>In c# when simulating a lan-messenger I am using the loopback address just for testing the current code and am being able to receive the first message I am sending.However after that there aren't any messages reaching the socket.Is there anything to do with clearing a socket buffer?.please help This is the callback function when a connection is made:</p> <pre><code>private void accepted(IAsyncResult iar) { Socket server = (Socket)iar.AsyncState; Socket client = server.EndAccept(iar); if (client.Connected) { try { client.BeginReceive(receive, 0, receive.Length, System.Net.Sockets.SocketFlags.None, new AsyncCallback(rec), client); } catch (ArgumentException) { MessageBox.Show("arguments incorrect in begin-receive call", "Error", MessageBoxButtons.OK); } catch (SocketException) { MessageBox.Show("error in accessing socket while receiving", "Error", MessageBoxButtons.OK); } catch (ObjectDisposedException) { MessageBox.Show("socket closed while receiving", "Error", MessageBoxButtons.OK); } catch (Exception) { MessageBox.Show("error while receiving", "Error", MessageBoxButtons.OK); } } </code></pre> <p>This is the callback function when the begin-receive method is executed:</p> <pre><code>void rec(IAsyncResult ar) { StringBuilder receivedData; //String oldvalue; Socket remote = (Socket)ar.AsyncState; int recv = remote.EndReceive(ar); receivedData = new StringBuilder(Encoding.ASCII.GetString(receive, 0, recv)); //MessageBox.Show(receivedData.ToString(), "received", MessageBoxButtons.OK); StringBuilder sb = new StringBuilder(this.textBox1.Text); sb.AppendLine(receivedData.ToString()); if (textBox1.InvokeRequired) { this.Invoke((MethodInvoker)delegate { this.textBox1.Text = sb.ToString(); }); } remote.Close(5); return; } </code></pre> <p>Does it have anything to do with a stringbuilder or string datatype for assigning the data received to a variable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload