Thanks
here is my code<
public void startServer()
{
int port = Convert.ToInt32(txtport.Text);
string ipaddre = getip();
IPAddress iP = IPAddress.Parse(ipaddre);
var serverSocket = new TcpListener(iP, port);
var clientSocket = default(TcpClient);
int counter = 0;
Form1 f1 = new Form1();
serverSocket.Start();
AppendTxtdata("Server Started , Waiting for Client Connection");
public void startServer()
{
int port = Convert.ToInt32(txtport.Text);
string ipaddre = getip();
IPAddress iP = IPAddress.Parse(ipaddre);
var serverSocket = new TcpListener(iP, port);
var clientSocket = default(TcpClient);
int counter = 0;
Form1 f1 = new Form1();
serverSocket.Start();
AppendTxtdata("Server Started , Waiting for Client Connection");
IsRunning = true;
try
{
while (IsRunning)
{
counter += 1;
clientSocket = serverSocket.AcceptTcpClient();
AppendTxtdata(" >> " + "Client No:" + Convert.ToString(counter) + " Connected-- IP --" + clientSocket.Client.RemoteEndPoint.ToString() + "");
AppendTxtdata(Environment.NewLine);
handleClient client = new connectSuccess.handleClient();
client.startClient(clientSocket, Convert.ToString(counter));
// break;
}
AppendTxtdata("Data sent to Client No :" + Convert.ToString(counter));
//clientSocket.Close();
//serverSocket.Stop();
}
catch { }
finally
{
clientSocket.Close();
serverSocket.Stop();
}
}
I don't have access of these objects out of this method.
Yashwanth MuthineniPosted Jul 17, 2015, 6:48 AM
I have two TCPClient objects TCPClientA and TCPClientB with different remote endpoints ports, but the same IP:
returns: 192.168.1.10:50001
returns: 192.168.1.10:50002
TCPClientA needs to be cleaned up because it's no longer useful, so I call
But this closes the socket for the client at the other end of TCPClientB, for some reason. However, writing
Successfully closes TCPClientA without interfering with TCPClientB. So I've fixed the problem, but I don't understand why it works that way.