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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server using Winsock on threads (Visual Basic 6)

Status
Not open for further replies.

stoorob

Programmer
Nov 27, 2000
6
GB
Hi,

Can anyone help me with a problem I have encountered recently while writing a client/server program that
allows multiple users to log in, save\retrieve records
in a SQL table and other such tasks.

Communication between the client and server is via Winsock.

The server is like :

One Winsock control for accepting user logon requests only.
Upon successfull request another winsock control (arrayed)
is loaded for that request to be carried out. This Winsock
handles all taks for that connection, so there coule be
many Winsok in this array if more than one client logs on
and performss requests.

The problem :

If the server is processing a users request and another client tries to log in or request something nothing happens
until the current client's process has been finished.

Does anyone know how I can overcome this problem? I have an idea that threads may be the soluton but have never used
them before. The client uses a dll to start any
communication the the server, the server has the winsock
contols built in to the main form - it appears that while
a process is in the DataArrival event no other data can arrive, even on another element of the Winsock array....

Can anyone help me with this?

Stuart Roberts
 
We have just solved the exact same problem.

The way we achieved it was to have a standard exe with a control array of WinSock controls (using SocketWrench instead of MS controls) for actual communication.

Within the exe we created a collection of objects (clsConversation), which contained the ids of the conversations.

We have an ActiveX DLL which is very very simple: One function call and event. This DLL implments a common interface which is used by the next part of the system.

The next part of the system is another ActiveX DLL which actually processes the messages.


When a conversation starts, a new WinSock control is created and an instance of clsConveration.

A method on clsConversation is called which creates an instance of the first ActiveX DLL. This makes a call to the second ActiveX DLL. The method called on the 2nd DLL actually stores the message in the object and starts a timer. The execution of the methods stops and control is passed back to the first DLL, which then passes back control to the EXE.

This means that EXE can process the next conversation with no waiting (the object creation is very fast).

When the timer event occurs in the second DLL, the actual processing is performed. When this is finished, a method is called on the first DLL with the outcome from the processing.

Calling the method in the first DLL, actually then raises an event which is captured in the EXE. The conversation details are then retrieved from the collection of objects (clsConversation), and the message sent back to the original client.


Hope this helps. Sorry if my explanation is not clear. Let me know if not.

Karl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top