Note that there are some explanatory texts on larger screens.

plurals
  1. POTCP Connection failed
    primarykey
    data
    text
    <p>I am tired to figuring out what wrong with my code... Please help me out here!</p> <p>I am trying to create a TCP connection between server client in LAN. What happens is, that the program crashes when client tries to connect. Please see the code:</p> <pre><code>public void Go() { if (whatjob == true) { IPEndPoint server_ipEndPoint = new IPEndPoint(IPAddress.Any, PortNum); server_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server_socket.Bind(server_ipEndPoint); try { server_socket.Listen(1); server_GotClient = server_socket.Accept(); } catch (SocketException e) { MessageBox.Show("Unable to listen..."); MessageBox.Show(e.ToString()); } reading = new Thread(new ThreadStart(this.get_msg)); reading.Start(); } if (whatjob == false) { IPEndPoint client_ipEndPoint = new IPEndPoint(IPAddress.Parse(IpAddress), PortNum); client_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { client_socket.Blocking = true; client_socket.Connect(client_ipEndPoint); //here it stops execution //client_socket.BeginConnect(client_ipEndPoint, new AsyncCallback(NowConnected), client_socket); } catch (SocketException e) { MessageBox.Show("Unable to connect..."); MessageBox.Show(e.ToString()); return; } reading = new Thread(new ThreadStart(this.get_msg)); reading.Start(); } </code></pre> <p>whatjob is bool... true means do server job and false means do client job</p> <p>this function is inside windows FORM for chat window. when it reaches until client_socket.connect(ipendpoint), it crashed and even chat window is deformated...</p> <p><strong>Threaded Function</strong></p> <pre><code>public void get_msg() { byte[] byte_message = new byte[1000]; string string_message = null; int x = 0; while (true) { if (server_GotClient != null) { x = server_GotClient.Receive(byte_message); } if (client_socket != null) { x = client_socket.Receive(byte_message); } if (x != 0) { string_message = Encoding.ASCII.GetString(byte_message); this.richTextBox_GetMessage.Invoke(new MethodInvoker(delegate { richTextBox_GetMessage.Text = richTextBox_GetMessage.Text + "\nFriend: " + string_message; })); } x = 0; } server_socket.Close(); } </code></pre> <p>Please help regarding this code. to add further, I have no knowledge of asynchronous techniques, help me with some easy methods.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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