Results 1 to 2 of 2

Thread: Winsock!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    5
    OK. I have been working on this problem for at least 2 weeks and it is probably a damn easy problem to solve but PLEASE HELK!!! Ready, here we go... I simply want my program to accept a max of 10 connections to WinSock. Therefore, what I did was create a Winsock control and called it WinsockMain. Then an array of 10 Winsock which are the real sockets. WinsockMain listens and when it receives a connection request, it passes the requestID to an open Winsock, and then closes and listens again. Look at the code:

    Private Sub WinsockMain_ConnectionRequest(ByVal requestID As Long)

    For i = 1 To 10
    If Winsock(i).State = 0 Then GoTo WinsockAvailable
    Next i

    WinsockMain.Close: DoEvents
    WinsockMain.Listen: DoEvents
    Exit Sub

    WinsockAvailable:
    Winsock(i).Accept requestID: DoEvents
    Winsock(i).SendData "Username: ": DoEvents
    MainState(i) = 1
    WinsockMain.Close: DoEvents
    WinsockMain.RemoteHost = ""
    WinsockMain.RemotePort = 0
    WinsockMain.Listen: DoEvents

    End Sub

    The MainState is just something in my program, so don't worry about it. Now, here's the problem. Everything works alright, and the user connects and is passed to an open Winsock. However, randomly (at least I think), when a user is connected, a second user cannot enter, it just doesn't find the open port. I checked the WinsockMain control and the state was 2 (listening) and the port was correct and everything. But it just doesn't find the opening! Then, when I log out of the 1 user connection, it magically finds the open port. Also, this problem sometimes occurs when the logged on user logs out. It's very strange. Any ideas?

  2. #2
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126
    Try...

    WinsockAvailable:

    ' that forces the socket to use a random inbound port
    ' thus free-ing up the listening port, you must use
    ' this method when doing multiple sockets.

    Winsock(i).LocalPort = 0
    Winsock(i).Accept requestID: DoEvents
    Winsock(i).SendData "Username: ":
    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

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