| | |
Server's mulitple listening
![]() |
•
•
Join Date: Feb 2007
Posts: 11
Reputation:
Solved Threads: 0
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
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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!
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!
•
•
Join Date: Feb 2007
Posts: 11
Reputation:
Solved Threads: 0
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...
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...
Last edited by varun.coolmax; Feb 19th, 2007 at 11:21 am.
You need to index the winsock controler, look in the properties. Set the index to 0. after that it should all work.
untitled.bmp
untitled.bmp
![]() |
Similar Threads
- Winsock Multi-Client Servers (C++)
- Java Client/Server (Java)
- Using PHP to connect to remote MSSQL database (PHP)
- URGENT: FTP Client / Server using RMI (Java)
- client server communication problem in CSocket program (C)
- Help with multithread server (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Tic-Tac-Toe Game
- Next Thread: need help with user and password
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows





