Results 1 to 3 of 3

Thread: [Resolved] Winsock Stuck on connecting...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [Resolved] Winsock Stuck on connecting...

    Well, the project that i'm making at the moment is a little long to post. But i will post the bit i'm having problems with.

    Here's a explanation of my variables:
    Is_Listen is a public boolean and it's used for checking if the winsock is listening or not. It's an array.

    Can_use Is a public boolean also. Is the winsock connected or not?

    LstWnSck.Text is a listbox that has all the winsocks listed in it.

    Refresh_WinCon_List updates the listbox that contains all the winsocks and it updates the Is_Listen and the Can_use Booleans


    Here's the waiting side:
    VB Code:
    1. Private Sub mWaitForConnection_Click()
    2.  
    3. If Len(PortTxt.Text) <= 0 Then
    4. MsgBox "You must specify a port number."
    5. Exit Sub
    6. End If
    7.  
    8. If Len(LstWnSck.Text) <= 0 Then
    9. MsgBox "You must specify a WinSock to be used."
    10. Exit Sub
    11. End If
    12.  
    13. FrmServer.WSServer(LstWnSck.Text).LocalPort = PortTxt.Text
    14. FrmServer.WSServer(LstWnSck.Text).Listen
    15. Is_Listen(LstWnSck.Text) = True
    16. Can_use(LstWnSck.Text) = False
    17.  
    18. End Sub

    Here's the connect to side:

    VB Code:
    1. Private Sub mConnectToThisIPUsingThisPort_Click()
    2. Dim Port_ As Variant
    3. Dim IP_ As Variant
    4.  
    5. On Error GoTo Errors
    6.  
    7. If Len(IPTxt.Text) >= 1 Then IP_ = IPTxt.Text
    8.  
    9. FrmServer.WSServer(LstWnSck.Text).Connect IP_, Port_
    10. Can_use(LstWnSck.Text) = False
    11.  
    12. Refresh_WinCon_List
    13.  
    14. Exit Sub
    15. Errors:
    16. MsgBox "There was an error, check the IP and the Port."
    17. Exit Sub
    18.  
    19. End Sub


    Here's the connection request inside the winsock
    VB Code:
    1. Private Sub WSServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    2.  
    3. If Is_Listen(Index) = True Then
    4. Is_Listen(Index) = False
    5. WSServer(Index).Close
    6. WSServer(Index).Accept requestID
    7. Can_use(Index) = False
    8. ServerConnectionsTxt.Text = Get_Connections 'Refresh how many connections there are
    9.  
    10. Exit Sub
    11. End If
    12.  
    13. 'Check for Idle Winsocks. If found use it
    14.  
    15. If WSServer.UBound >= 2 Then
    16. For io = 1 To WSServer.UBound
    17. If WSServer(WSServer.UBound).State = 0 Then Can_use(WSServer.UBound) = True
    18. If Can_use(WSServer.UBound) = True Then
    19. WSServer(WSServer.UBound).Accept requestID
    20. GoTo Connection_Made
    21. Exit Sub
    22. End If
    23. Next io
    24. End If
    25.  
    26. 'If there's no idle WinSocks then add a new one
    27.  
    28. Load WSServer(WSServer.UBound + 1)
    29.  
    30. WSServer(WSServer.UBound).Accept requestID
    31. Can_use(WSServer.UBound) = False
    32.  
    33. ServerConnectionsTxt.Text = Get_Connections 'Refresh how many connections there are
    34.  
    35. Connection_Made:
    36.  
    37. End Sub

    I want winsock 0 to always be listening, however i want every other winsock to do what ever.

    Now unless you want the full project don't worry about the other stuff, lol.

    When i use winsock 0 it works fine. When i listen on another winsock it listens, but if i goto another computer on my LAN and try to connect to the listening winsock (i'm using the computer's correct IP and the port that the computer is connecting on is the same port as the other computer is listening on) but for some reason. The winsock is stuck on state 6. Which is connecting. I've disabled all my firewalls and i'm behind a router.

    Here's the real project. I'm making a server chat program. I'm trying to make it really advanced so that it can host web pages too. It's no where finished and there's alot of features that haven't been done yet. Also there's msgboxes that will show up that i'm using for debugging. Frmserver is where the winsocks are located (WSServer) and the form that i'm having this problem with is FrmDataCentre. Most of my code is uncommented. and not structured apart from my own style.










    Added green "resolved" checkmark - Hack
    Attached Files Attached Files
    Last edited by Hack; Jan 17th, 2006 at 12:02 PM.

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Winsock Stuck on connecting...

    just to double check when winsock 0 is listening you can connect fine from another pc on the LAN using your WAN IP ?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Winsock Stuck on connecting...

    Yeah, i found the error after ripping my hair out

    VB Code:
    1. Dim Port_ As Variant
    2. Dim IP_ As Variant
    3.  
    4. On Error GoTo Errors
    5.  
    6. If Len(IPTxt.Text) >= 1 Then IP_ = IPTxt.Text
    7.  
    8. FrmServer.WSServer(LstWnSck.Text).Connect IP_, Port_

    Because it's a variant, for some reason it was setting the port to 0. So when i clicked connect it found the IP but nothing listening on that port and that's why it said connecting on state 6. It was waiting for somthing on port 0. Thanks for you help any ways.

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