i've got a project wherein the server listens only from one client on one port...i want a program to make the server lsiten to multiple clients on same port or different ports...watever....can anyone help me out. the foll is my Server side Code

Private Sub cmdStartListening_Click()
'listens for client requests

On Error GoTo error_handle_for_listening
' In case there is any error, this will jump to the
' "error_handle_for_listening" section

Winsock1.Close
' We close it in case its listening before

Winsock1.LocalPort = txtPortno.Text
' Local port of the winsock control is the text value entered in "txtPortno"

Winsock1.Listen
'Start listening

Exit Sub

error_handle_for_listening:
'Block for error handeling

MsgBox "Error : " & Err.Description, vbCritical
'This will display the error generated by the winsock control.

End Sub



Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
'This function is used to handle the connection initiation be the client
'This event is triggered when a client try to connect on our host
'We must accept the request for the connection to be completed

If Winsock1.State <> sckClosed Then Winsock1.Close
'Check if the state of the winsock connection
'If the state is closed, then the Connection is closed

Winsock1.Accept requestID
'With this we can accept the connection from the clients &
'then start sending / receiving the Data

rtbMainConsole.Text = " Client Connected. IP = " & Winsock1.RemoteHostIP & vbCrLf
'Display the Client connected & its IP address

rtbMainConsole.SelStart = Len(rtbMainConsole)
'This is used to autoscroll down the Main Chat Console

End Sub



Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'This is being trigger every time new data arrive from the client

Dim strData As String
'The incomming data is received & saved in this variable

Winsock1.GetData strData, vbString
'The wisock connection is received here

rtbMainConsole.Text = rtbMainConsole.Text & "Client : " & strData & vbCrLf
'Displays the received data in the main chat console

rtbMainConsole.SelStart = Len(rtbMainConsole)
'This is used to autoscroll down the Main Chat Console

End Sub

This is it....also i need to send data files..is it possible to do it using the "winsock data arrival function" in my program...jus a query i wanted to clarify

This how I have been doing that.

requires a timer => conncheck
winsock control => p2p(0)

Private Sub conncheck_Timer()
Dim a As Integer
If p2p(p2p.UBound).State = 8 And p2p.UBound > 0 Then
Unload p2p(p2p.UBound)
End If
GoTo finalTimerConnections
endTimerConnections:
On Error Resume Next
finalTimerConnections:
p2p(0).Close
p2p(0).Listen
End Sub

Private Sub Form_Load()
p2p(0).Listen
End Sub

Private Sub p2p_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Load p2p(p2p.UBound + 1)
p2p(0).Close
p2p(p2p.UBound).Accept requestID
p2p(0).Listen
End Sub

Hope that helped some!

CRicket2030's
thanx for putting in time for this ....but dude i am not getting the thing of a winsock controller name having a parenthesis...also...i didn get the ubound part...that doesn seem to come in my method list for a winsock controler of VB6....sorry but can u explain me some of this stuff...

You need to index the winsock controler, look in the properties. Set the index to 0. after that it should all work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.