Server/Client with Winsock Control. 
Author Message
 Server/Client with Winsock Control.

Hi All!

        I'm writing a server/client application, except that there will be one
server and potentially many clients accessing that server.  It seems to
me that for a server application to accept many client connections, the
server would have to have many Winsock controls on it, one for each
connection.  But it doesn't sound plausible to cover a form in Winsock
connections, and that there must be a better way.

        Does anyone know the standard way of doing this?  Thanks!

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Website : http://www.*-*-*.com/ |    Phone :             480.858.0429
ICQ #   : 2462711                 | Location :           Tempe, AZ  USA
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Sun, 02 Jun 2002 03:00:00 GMT  
 Server/Client with Winsock Control.
Hi All!

        I'm writing a server/client application, except that there will be
one
server and potentially many clients accessing that server.  It seems to me
that for a server application to accept many client connections, the server
would have to have many Winsock controls on it, one for each connection.  But
it doesn't sound plausible
 to cover a form in Winsock connections, and that
there must be a better way.

        Does anyone know the standard way of doing this?  Thanks!

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Website : http://www.dcs-home.com |    Phone :             480.858.0429
ICQ #   : 2462711                 | Location :           Tempe, AZ  USA
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Sun, 02 Jun 2002 03:00:00 GMT  
 Server/Client with Winsock Control.
Nick,

You're right, there is a standard way of doing this.  Here's some info from
the Winsock help text.  It outlines the way to set up Winsock as a control
array and pass off each new connection request to a new instance of the
control.

Nick R.

Accepting More than One Connection Request
The basic server outlined above accepts only one connection request.
However, it is possible to accept several connection requests using the same
control by creating a control array. In that case, you do not need to close
the connection, but simply create a new instance of the control (by setting
its Index property), and invoking the Accept method on the new instance.

The code below assumes there is a Winsock control on a form named sckServer,
and that its Index property has been set to 0; thus the control is part of a
control array. In the Declarations section, a module-level variable intMax
is declared. In the form's Load event, intMax is set to 0, and the LocalPort
property for the first control in the array  is set to 1001. Then the Listen
method is invoked on the control, making it the "listening control. As each
connection request arrives, the code tests to see if the Index is 0 (the
value of the "listening" control). If so, the listening control increments
intMax, and uses that number to create a new control instance. The new
control instance is then used to accept the connection request.

Private intMax As Long

Private Sub Form_Load()
   intMax = 0
   sckServer(0).LocalPort = 1001
   sckServer(0).Listen
End Sub

Private Sub sckServer_ConnectionRequest _
(Index As Integer, ByVal requestID As Long)
   If Index = 0 Then
      intMax = intMax + 1
      Load sckServer(intMax)
      sckServer(intMax).LocalPort = 0
      sckServer(intMax).Accept requestID
      Load txtData(intMax)
   End If
End Sub


Quote:
> Hi All!

> I'm writing a server/client application, except that there will be one
> server and potentially many clients accessing that server.  It seems to
> me that for a server application to accept many client connections, the
> server would have to have many Winsock controls on it, one for each
> connection.  But it doesn't sound plausible to cover a form in Winsock
> connections, and that there must be a better way.

> Does anyone know the standard way of doing this?  Thanks!

> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

> Website : http://www.dcs-home.com |    Phone :             480.858.0429
> ICQ #   : 2462711                 | Location :           Tempe, AZ  USA
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Mon, 03 Jun 2002 03:00:00 GMT  
 Server/Client with Winsock Control.
Nick,

You're right, there is a standard way of doing this.  Here's some info from
the Winsock help text.  It outlines the way to set up Winsock as a control
array and pass off each new connection request to a new instance of the
control.

Nick R.

Accepting More than One Connection Request The basic server outlined above
accepts only one connection request. However, it is possible to accept
several connection requests using the same control by creating a control
array. In that case, you do not need
 to close the connection, but simply
create a new instance of the control (by setting its Index property), and
invoking the Accept method on the new instance.

The code below assumes there is a Winsock control on a form named sckServer,
and that its Index property has been set to 0; thus the control is part of a
control array. In the Declarations section, a module-level variable intMax is
declared. In the form's
 Load event, intMax is set to 0, and the LocalPort
property for the first control in the array  is set to 1001. Then the Listen
method is invoked on the control, making it the "listening control. As each
connection request arrives, the code tests to see i
f the Index is 0 (the
value of the "listening" control). If so, the listening control increments
intMax, and uses that number to create a new control instance. The new
control instance is then used to accept the connection request.

Private intMax As Long

Private Sub Form_Load()
   intMax = 0
   sckServer(0).LocalPort = 1001
   sckServer(0).Listen
End Sub

Private Sub sckServer_ConnectionRequest _ (Index As Integer, ByVal requestID
As Long)
   If Index = 0 Then
      intMax = intMax + 1
      Load sckServer(intMax)
      sckServer(intMax).LocalPort = 0
      sckServer(intMax).Accept requestID
      Load txtData(intMax)
   End If
End Sub


Quote:
> Hi All!

> I'm writing a server/client application, except that there will be one
> server and potentially many clients accessing that server.  It seems to
> me that for a server application to accept many client connections, the
> server would have to have many Winsock controls on it, one for each
> connection.  But it doesn't sound plausible to cover a form in Winsock
> connections, and that there must be a better way.

> Does anyone know the standard way of doing this?  Thanks!

> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

> Website : http://www.dcs-home.com |    Phone :             480.858.0429
> ICQ #   : 2462711                 | Location :           Tempe, AZ  USA
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Mon, 03 Jun 2002 03:00:00 GMT  
 Server/Client with Winsock Control.
But what about releasing the sockets when the clients disconnect?
With the scheme outlined in the example the variable intMax will just
continue growing and more and more sockets get created and linger
around. Memory and resources might get consumed this way.
How do you make sure this will not happen?

/Bo

On Thu, 16 Dec 1999 00:35:50 GMT+0600,

Quote:

>Nick,

>You're right, there is a standard way of doing this.  Here's some info from
>the Winsock help text.  It outlines the way to set up Winsock as a control
>array and pass off each new connection request to a new instance of the
>control.

>Nick R.

>Accepting More than One Connection Request The basic server outlined above
>accepts only one connection request. However, it is possible to accept
>several connection requests using the same control by creating a control
>array. In that case, you do not need
> to close the connection, but simply
>create a new instance of the control (by setting its Index property), and
>invoking the Accept method on the new instance.

>The code below assumes there is a Winsock control on a form named sckServer,
>and that its Index property has been set to 0; thus the control is part of a
>control array. In the Declarations section, a module-level variable intMax is
>declared. In the form's
> Load event, intMax is set to 0, and the LocalPort
>property for the first control in the array  is set to 1001. Then the Listen
>method is invoked on the control, making it the "listening control. As each
>connection request arrives, the code tests to see i
>f the Index is 0 (the
>value of the "listening" control). If so, the listening control increments
>intMax, and uses that number to create a new control instance. The new
>control instance is then used to accept the connection request.

>Private intMax As Long

>Private Sub Form_Load()
>   intMax = 0
>   sckServer(0).LocalPort = 1001
>   sckServer(0).Listen
>End Sub

>Private Sub sckServer_ConnectionRequest _ (Index As Integer, ByVal requestID
>As Long)
>   If Index = 0 Then
>      intMax = intMax + 1
>      Load sckServer(intMax)
>      sckServer(intMax).LocalPort = 0
>      sckServer(intMax).Accept requestID
>      Load txtData(intMax)
>   End If
>End Sub



>> Hi All!

>> I'm writing a server/client application, except that there will be one
>> server and potentially many clients accessing that server.  It seems to
>> me that for a server application to accept many client connections, the
>> server would have to have many Winsock controls on it, one for each
>> connection.  But it doesn't sound plausible to cover a form in Winsock
>> connections, and that there must be a better way.

>> Does anyone know the standard way of doing this?  Thanks!

>> --
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

>> Website : http://www.dcs-home.com |    Phone :             480.858.0429
>> ICQ #   : 2462711                 | Location :           Tempe, AZ  USA
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Bo Berglund
Software developer in Sweden

PGP: My public key is available at the following locations:
Idap://certserver.pgp.com
http://pgpkeys.mit.edu:11371



Fri, 14 Jun 2002 03:00:00 GMT  
 Server/Client with Winsock Control.

Quote:

> But what about releasing the sockets when the clients disconnect?
> With the scheme outlined in the example the variable intMax will just
> continue growing and more and more sockets get created and linger
> around. Memory and resources might get consumed this way.
> How do you make sure this will not happen?

Search the array first looking for a closed socket that you can re-
use.  You only add one if none are available.  When the app ends you
should close & unload all of the sockets.  For a very simple example
see http://home.earthlink.net/~butlerbob/vb/network/tcpip/server.htm

Sent via Deja.com http://www.deja.com/
Before you buy.



Fri, 14 Jun 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. winsock control: determine server's port from client

2. Winsock control client and MFC CSocket server

3. Need Winsock control on both client and server?

4. Winsock control question on the client quantity allowed to connect to the server

5. winsock code sample for client-server in .Net

6. winsock help..client and server

7. Winsock API client server app

8. Advanced VB5 Client/Server winsock question

9. Winsock Client / Server problem

10. Client/Server - Sending a file through WinSock ..

11. Winsock Server handling multiple clients access

12. Winsock client cannot connect to server

 

 
Powered by phpBB® Forum Software