Generic Client/Server app sample source code.

S

Sin Jeong-hun

I need to write little applications with c/s model. I need basic
features like,
1)The server should be able to handle multiple clients at the same
time. (multithreaded)
2)The clients and the server can send and receive data.

I think these could be very generic requirements. I searched the
internet for samples where I can get started, but the source codes were
too simple and showed unrealistic behaviours. I mean those examples
just send a string and then receive a string then exit in the main
method. No concurrent send/receive between server/clients. Isn't there
any example that shows more realistic sample programs where for the
server, a listening thread keeps running and passes the event to the
UI. And for the client,something like a send method and a received
event? Sorry if my explination is too vague , I'll write a pseudo
program below. I think these server and client classes are so generic
that they could be a library and reused in my applications. So is there
any article or sample program like these? Thank you for reading this.

----Server-
(form's init)
Server server = new Server(12345);
server.ClientDataReceived+=OnClientDataReceived....
server.Start()

void OnClientDataReceived(Client sender, object data)
{
...
server.Send(sender,....);
}

--------Client
(form's init)
Client client = new Client("127.0.0.1", 12345);
client.Connect();

void OnSendButtonClicked(..)
{
client.Send(....)
}

void OnQuitButtonClicked(...)
{
client.Close();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top