Results 1 to 5 of 5

Thread: winsock enhancement...(URGENT)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    philippines
    Posts
    245

    winsock enhancement...(URGENT)

    do any one ha a code for this:

    1) i have a socket Server that listens(ARRAY)
    2) i have a client socket that connects to server.
    3) if i connect 5 clients and socket(3) closes, if i open
    another client, i want it to connect to socket(3) and not load
    another control so that the number of sockets is reduced.


    I'm stuck with this **** part. but my app is running fine it's just i want to make it more efficient and resource friendly.

    IF you have any code for this i'd appreciate it. thanks.

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    or you can just Unload the winsock control after it has closed.....
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    philippines
    Posts
    245
    do you have the code? can i see it?i will post the code of the server. then can you jsut edit it?

    VB Code:
    1. Private intMax As Long
    2. Private PMer As String
    3. Private cfgPath As String
    4.  
    5. Private Sub Form_Load()
    6.    cfgPath = App.Path & "\logs.cfg"
    7.    intMax = 0
    8.    Winsock1(0).LocalPort = 1234
    9.    Winsock1(0).Listen
    10. End Sub
    11.  
    12. Private Sub Form_Unload(Cancel As Integer)
    13.     Call WriteIni(cfgPath, Date, "[ " & Time & " ]", txtMsgBoard.Text)
    14. End Sub
    15.  
    16. Private Sub winsock1_ConnectionRequest _
    17. (index As Integer, ByVal requestID As Long)
    18.     intMax = intMax + 1
    19.     Load Winsock1(intMax)
    20.     Winsock1(intMax).LocalPort = 0
    21.     Winsock1(intMax).Accept requestID
    22.     DoEvents
    23.     Winsock1(intMax).SendData "connected"
    24. End Sub
    25.  
    26. Private Sub Winsock1_DataArrival(index As Integer, ByVal bytesTotal As Long)
    27. Dim strdata As String, x As Integer, y As Integer
    28. On Error Resume Next
    29.     Winsock1(index).GetData strdata
    30.    
    31.     If Left$(strdata, 4) = "nick" Then
    32.         lstNicks.AddItem Mid(strdata, 5, Len(strdata))
    33.         For x = Winsock1.LBound To Winsock1.UBound
    34.             Winsock1(x + 1).SendData Mid(strdata, 5, Len(strdata)) & " has connected"
    35.             DoEvents
    36.             Winsock1(x + 1).SendData "nicklist" & getNickList
    37.             DoEvents
    38.         Next
    39.     End If
    40.    
    41.     If Left$(strdata, 10) = "disconnect" Then
    42.         lstNicks.RemoveItem getIndex(Mid(strdata, 11, Len(strdata)))
    43.         Winsock1(index).Close
    44.         For x = Winsock1.LBound To Winsock1.UBound
    45.             Winsock1(x + 1).SendData "delnick" & Mid(strdata, 11, Len(strdata))
    46.             DoEvents
    47.         Next
    48.     End If
    49.    
    50.     If Left$(strdata, 4) <> "nick" And Left$(strdata, 8) <> "nicklist" Then
    51.         For x = Winsock1.LBound To Winsock1.UBound
    52.             Winsock1(x + 1).SendData strdata
    53.         Next
    54.         txtMsgBoard.Text = txtMsgBoard.Text & strdata & vbCrLf
    55.     End If
    56.     txtMsgBoard.SelStart = Len(txtMsgBoard.Text)
    57. End Sub
    58.  
    59. Private Function getNickList() As String
    60. Dim x As Integer, myStr As String
    61.     For x = 0 To lstNicks.ListCount
    62.         myStr = myStr & " " & lstNicks.List(x)
    63.     Next
    64.     getNickList = myStr
    65. End Function
    66.  
    67. Private Function getIndex(myText As String) As Integer
    68. Dim x As Integer
    69.     For x = 0 To lstNicks.ListCount
    70.         If lstNicks.List(x) = myText Then
    71.             getIndex = x
    72.         End If
    73.     Next
    74. End Function

  4. #4
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    there should be a sub similar (not exactly) to

    Winsock_Close(Index as integer)

    put the following code, adjust the names of the control:

    Unload winsock(index)
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    You should do a search on the forum before you post here...
    Anyways... I did that for you, and I got lots of rezults, + one of mine
    Take a look at ConnectionRequest event for this server...
    http://www.vbforums.com/showthread.p...hlight=winsock

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width