I’m making an application server client using tcp sockets in c# ..
The application has multi tasks like file transfer .. file manager .. chat .. (voice chat later)
So I decided to create a socket to receive the commands as a string
and another socket to transfer files ..
is that a good way for programming a server-client application or should I try another way?
because user could send a message while receiving/sending a file
and how could I tell the (file-transfer-server) accept only the same client who has already connected with the main server
ex: server listen on port 8000 and accept clients .. and file transfer on port 8111
public StartSever()
{
sr = new StreamReader(networkStream);
while(connected)
{
string[] command = sr.ReadLine().split(',');
switch (Command[0])
{
case "RecFile":
StartFileTransferServer(); // creating new socket tcp listens on port 8111
Receiving();
break;
case "SendFile":
StartFileTransferServer(); // creating new socket tcp listens on port 8111
Sending();
break;
case "Chat":
chat(Command[1]);
break;
default:
break;
}
}
You could use some kind of communication framework or library which would abstract the details of TCP/IP sockets and allow you to send objects and messages and files between your client and server end and not have to worry about all the details.
Some things you could look into using instead:
Those are just some examples I thought of off of the top of my head there are tons of such frameworks that work at different levels of abstraction and offer more heavy or light weight implementations. I’m sure you could find one that meets your basic needs.