Allow Multiple Winsock Connections to One Server

The Winsock control allows you to make only one connection between two computers. However, you can create multiple connections (many computers to one) by creating multiple instances of the Winsock control at run time.

Add a Winsock control to your form and set its index to 0, then add this code into the server machine to allow multiple connections to it:

 Option ExplicitPublic NumSockets As Integer'//Public Variable to track number of ConnectionsPrivate Sub Form_Load()	Caption = Winsock1(0).LocalHostName & _		Winsock1(0).LocalIP	Winsock1(0).LocalPort = 1066	Print "Listening to " + Str(Winsock1(0).LocalPort)	Winsock1(0).ListenEnd SubPrivate Sub Winsock1_Close(Index As Integer)	Print "Connection Closed :" & _		Winsock1(Index).RemoteHostIP	Winsock1(Index).CloseEnd SubPrivate Sub Winsock1_ConnectionRequest(Index As Integer, _	ByVal requestID As Long)	Print "Connection Request from : " & _		Winsock1(Index).RemoteHostIP	NumSockets = NumSockets + 1	'//Increase Number of Sockets by one.	Load Winsock1(NumSockets)	'//Load a New Winsock Object Nusockets as Index Value	Winsock1(NumSockets).Accept requestID	'//Accept the New ConnectionEnd SubPrivate Sub Winsock1_DataArrival(Index As Integer, ByVal _	bytesTotal As Long)	Dim vtData As String	Winsock1(Index).GetData vtData, vbString	Print vtDataEnd Sub

You should now be able to continue to accept connections from multiple sources.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: