I have a client server application [TCP Sockets, .NET 4.0] ..
application about:
execute commands received from the client receives files send screenshot image
the application must perform 3 tasks at the same time
After I did this and it worked .. I realized that such an application should use one port for all tasks. For example, Radmin and netsupport .. etc.
but I used 3 ports .. one to keep receiving commands anytime the client sends. and one for receiving files .. and one if the client asked for a screenshot
is it good to use 3 ports for a network application? ..
I tried to create 3 sockets on the client side to connect to the server on the same port (ex: 9090)
but when I tried to send the file with the client, the server received bytes in the Job function, which should only accept commands ... so it looks like I can not use one port for these tasks, so it is possible to use one port for all three tasks that they can work simultaneously?
private void ClientAccept() { while (true) { Socket client = server.Accept(); Console.WriteLine(client.RemoteEndPoint + " has connected"); NetworkStream stream = new NetworkStream(client); StreamReader reader = new StreamReader(stream); string line = reader.ReadLine(); if (line == "1") //it means its a command socket { thJob = new Thread(Job); thJob.Start(cmdClient); } else if(line=="2") //its a data socket { FileTransfer ft = new FileTransfer(client); } } } private void Job(object o) { Socket s = (Socket)o; StreamReader sr = new StreamReader(new NetworkStream(s)); string cmd = null; while ((cmd = sr.ReadLine()) != null) { //bla bla } }
Question added:
let's say the server has one port.
the client will connect to the server for commands .. let it call cmdClient, which has port 11589, then Job Thread, such as the up code, was launched for this client. then the client connects to another socket on the server .. dataClient, which its port is 1800, then when I use dataClient to send the file .. the server receives bytes in the Method task .. !! Why is this happening?
source share