locked
Sockets - Handling disconnects/reconnects RRS feed

  • Question

  •  

    I have a relatively simpe client/server application which I'm trying to send a signal from the client that it wishes to disconnect.  I've never done this before so if there's a better way to send a "disconnect signal" then please inform me.

     

    Right now if a user wishes to disconnect they click close and I have my code send the word "Disconnect" which the server looks for and initiates a disconnect procedure when it finds it (or rather thats what's supposed to happen).

     

     

    //Server checks for the "disconnect signal" which is simply a string that says "Disconnect".

    if (szData.Contains("Disconnect"))

    {

    theSockId.thisSocket.Disconnect(true);

    //theSockId.thisSocket.Shutdown(SocketShutdown.Both);

    //theSockId.thisSocket.Close();

    theSockId.thisSocket = null;

    //EnableCommands(true);

    }

    else

    {

    txtDataRx.Text = txtDataRx.Text + szData;

    WaitForData(m_socWorker);

    }

     

    The code allows you to connect and send data to the server, but once you disconnect and reconnect no more data will transmit and no exceptions are thrown.

    Monday, February 25, 2008 6:28 PM