# Instant Messenger - Multi threaded socket Programming



## adeel_bm (Jun 13, 2008)

Good morning,

I am willing to implement an instant messaging client server network application, likewise Live messenger form Microsoft and Yahoo! IM

The scene is; I am using one stream reader, hence one port in a while loop, to bring about multiple tasks.
1- Explicitly, the server would register a client from the welcome socket and then a thread would be created for a client. In that thread there would be a streamreader and a streamwriter. The reader would just pass the message to writer and the writer would pass that message to the destination; i.e. the client to whom this thread belongs. Now, the at the client app, there would be *a* reader which would parse the message, probably an xml wrapped message and do the appropriate action. Like to show a text message in a corresponding window, it would take the window id and show the message in that window. 
The reader at client application would be one, running in a separate thread and in a non terminating while loop. This means there would be only one port for my application. Suppose, a client starts receiving files from multiple clients with text messages, then the reader would be overloaded and delay wold be prominent.
Is that the reason Live messenger and others use multiple (TCP/UDP) ports for file sharing and text messaging and voice conversation and video packets?
Should i use separate ports for these tasks either? Can someone provide me a multithreading flowchart (functional prototype) for the basic instant messenger’s client program (also server if possible), that how different threads communicate with server and how these threads communicates with the multiple chat windows?
The language can be C# or Borland Java.
2- Should i use synch in java or semaphores in C# as compulsory somewhere in the program? If yes then wots the substitute keyword for synchronized (java) in C#, if one don’t want to use semaphore class and don’t want to experience its complexity?

Please help.
Regards,
Adeel 

THERE IS NOT D IN W
Thanks for curing my curiosity


----------

