Click here to Skip to main content
15,063,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Can some one help me on this.

I have a windows service using c#.net and created server and client for communicate/transfer messages each one by using the socket communication with TLS 1.2 security.

I am able to start the multiple ports at a time.
When I connect to specific port(2222) able to send/receive messages,
then I disconnected client and the same time server side also disconnected that port(2222), It has been stopped listening state in server side.
If I want send message again, not able to connecting to port 2222.

Another issue, I started 5 (1111,2222,3333,4444,5555) ports in the same time, but only last port 5555 is able to listen always, remaining are all closed.

How to make those ports also should listen always in server side.

Am attaching my code please correct this.

for (int i = _nUpdatedPorts; i <= _dtCustomerDetails.Rows.Count - 1; i++)
{
_serverIp = _dtCustomerDetails.Rows[i][3].ToString();
_intPortnumber = Convert.ToInt32(_dtCustomerDetails.Rows[i][4]);

try
{
_myList = new TcpListener(IPAddress.Parse(_serverIp), _intPortnumber);
_myList.Start();
var mythread = new Thread(new ThreadStart(SListenClient));
mythread.IsBackground = true;
mythread.Start();

}
catch (Exception ex)
{
return;
}
}

private void SListenClient()
{
_myClient = null;

try
{
while (true)
{
_myClient = _myList.AcceptTcpClient();
if (_myClient == null) continue;
_sslStream = ProcessClient(_myClient, _certificate);
if (_sslStream == null) continue;
if (!_sslStream.IsAuthenticated) continue;
var user = new Users(_myClient);
var thread = new Thread(() => ReceiveData(user, _sslStream)) { IsBackground = true };
thread.Start();
_userList.Add(user);
}
}
catch (Exception ex)
{

}
}

Thanks in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900