I am using TcpClient For a simple example of Socket Connection.
when the client connects :
clientSocket.Connect("192.168.1.3", 8888);
label1.Text = @"connecting...";
The client have to send me some data to the server (an english word), the server will then process that data, and return the result (definition of that word) ! after that the connexion must be stopped ! (when i say connexion needs to be stop i have no idea what i need to close and what i need to dispose)
anyway to stop which one of those should i use :
clientSocket.Client.Shutdown(SocketShutdown.Both);
clientSocket.Client.Dispose();
clientSocket.GetStream().Close();
clientSocket.Close();
my first problem is that when i try to connect again to the server with the same client (reuse the clientSocket) it gives me this exception, and it marks the clientSocket :
Message=Cannot access a disposed object.
Object name: 'System.Net.Sockets.TcpClient'.
Source=System
ObjectName=System.Net.Sockets.TcpClient
my sec problem is : to inform the client that the server want him to stop the connexion, it send a string message : "$" ! so each time the client receive a message, it checks if it is "$", if yes ! it start closing... im sure there is a better way to do that, can you please help me, thank you.