Server's mulitple listening

Reply

Join Date: Feb 2007
Posts: 11
Reputation: varun.coolmax is an unknown quantity at this point 
Solved Threads: 0
varun.coolmax varun.coolmax is offline Offline
Newbie Poster

Server's mulitple listening

 
0
  #1
Feb 18th, 2007
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Private Sub cmdStartListening_Click()
  3. 'listens for client requests
  4.  
  5. On Error GoTo error_handle_for_listening
  6. ' In case there is any error, this will jump to the
  7. ' "error_handle_for_listening" section
  8.  
  9. Winsock1.Close
  10. ' We close it in case its listening before
  11.  
  12. Winsock1.LocalPort = txtPortno.Text
  13. ' Local port of the winsock control is the text value entered in "txtPortno"
  14.  
  15. Winsock1.Listen
  16. 'Start listening
  17.  
  18. Exit Sub
  19.  
  20. error_handle_for_listening:
  21. 'Block for error handeling
  22.  
  23. MsgBox "Error : " & Err.Description, vbCritical
  24. 'This will display the error generated by the winsock control.
  25.  
  26. End Sub
  27.  
  28.  
  29.  
  30. Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
  31. 'This function is used to handle the connection initiation be the client
  32. 'This event is triggered when a client try to connect on our host
  33. 'We must accept the request for the connection to be completed
  34.  
  35. If Winsock1.State <> sckClosed Then Winsock1.Close
  36. 'Check if the state of the winsock connection
  37. 'If the state is closed, then the Connection is closed
  38.  
  39. Winsock1.Accept requestID
  40. 'With this we can accept the connection from the clients &
  41. 'then start sending / receiving the Data
  42.  
  43. rtbMainConsole.Text = " Client Connected. IP = " & Winsock1.RemoteHostIP & vbCrLf
  44. 'Display the Client connected & its IP address
  45.  
  46. rtbMainConsole.SelStart = Len(rtbMainConsole)
  47. 'This is used to autoscroll down the Main Chat Console
  48.  
  49. End Sub
  50.  
  51.  
  52.  
  53. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  54. 'This is being trigger every time new data arrive from the client
  55.  
  56. Dim strData As String
  57. 'The incomming data is received & saved in this variable
  58.  
  59. Winsock1.GetData strData, vbString
  60. 'The wisock connection is received here
  61.  
  62. rtbMainConsole.Text = rtbMainConsole.Text & "Client : " & strData & vbCrLf
  63. 'Displays the received data in the main chat console
  64.  
  65. rtbMainConsole.SelStart = Len(rtbMainConsole)
  66. 'This is used to autoscroll down the Main Chat Console
  67.  
  68. 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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 16
Reputation: cricket2030 is an unknown quantity at this point 
Solved Threads: 2
cricket2030's Avatar
cricket2030 cricket2030 is offline Offline
Newbie Poster

Re: Server's mulitple listening

 
0
  #2
Feb 19th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 11
Reputation: varun.coolmax is an unknown quantity at this point 
Solved Threads: 0
varun.coolmax varun.coolmax is offline Offline
Newbie Poster

Re: Server's mulitple listening

 
0
  #3
Feb 19th, 2007
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...
Last edited by varun.coolmax; Feb 19th, 2007 at 11:21 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 16
Reputation: cricket2030 is an unknown quantity at this point 
Solved Threads: 2
cricket2030's Avatar
cricket2030 cricket2030 is offline Offline
Newbie Poster

Re: Server's mulitple listening

 
0
  #4
Feb 19th, 2007
You need to index the winsock controler, look in the properties. Set the index to 0. after that it should all work.

untitled.bmp
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC