Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

socket server application

Status
Not open for further replies.

leangross

IS-IT--Management
Jul 3, 2002
84
PH
hi could anyone help me on this one. I already created a server application (listener) and a client application. my problem right now is how could the listener allow a multiple client connecting to it simultaneously?

I know the beginaccept. beginreceive, beginsend are the methods i should use. but how will the application know from which client it is reading from?

will the beginaccept method creates a new thread automatically?

Below is the logic how client sends data to server application,

Client:
- Start connection
- Send Fileheader
- send Filecontent
- Send another FileHEader
- send another filecontent
- accept a response from the listerner based on the information inside the file
_ end connection

Note: client can send different kind of information in one socket connection.


Server (listener)
- accept connection
- read info from client
- process the filecontent
- read another fileheader
- read another filecontents
- reply back to the client

Does anyone have any idea how to solve this? a sample working code will be great thanks!!!


 
Essentially you'll need to create multiple socket objects (from the listener Accept/BeginAccept), and store them in a collection and starting the Read so that it's listening for incoming data.

To determine which one is receiving data (in a Receive callback method) use the socket object itself as the State parameter in the BeginReceive method. You can then determine that during the callback method via the AsyncState of the IAsyncResult object the callback method requires for asynchronous calls.

Take a look at this wrapper for the socket called Winsock2007 - it makes handling multiple connections easy (not to mention network communication):
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top