1 Attachment(s)
[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:
Private Sub mWaitForConnection_Click()
If Len(PortTxt.Text) <= 0 Then
MsgBox "You must specify a port number."
Exit Sub
End If
If Len(LstWnSck.Text) <= 0 Then
MsgBox "You must specify a WinSock to be used."
Exit Sub
End If
FrmServer.WSServer(LstWnSck.Text).LocalPort = PortTxt.Text
FrmServer.WSServer(LstWnSck.Text).Listen
Is_Listen(LstWnSck.Text) = True
Can_use(LstWnSck.Text) = False
End Sub
Here's the connect to side:
VB Code:
Private Sub mConnectToThisIPUsingThisPort_Click()
Dim Port_ As Variant
Dim IP_ As Variant
On Error GoTo Errors
If Len(IPTxt.Text) >= 1 Then IP_ = IPTxt.Text
FrmServer.WSServer(LstWnSck.Text).Connect IP_, Port_
Can_use(LstWnSck.Text) = False
Refresh_WinCon_List
Exit Sub
Errors:
MsgBox "There was an error, check the IP and the Port."
Exit Sub
End Sub
Here's the connection request inside the winsock
VB Code:
Private Sub WSServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Is_Listen(Index) = True Then
Is_Listen(Index) = False
WSServer(Index).Close
WSServer(Index).Accept requestID
Can_use(Index) = False
ServerConnectionsTxt.Text = Get_Connections 'Refresh how many connections there are
Exit Sub
End If
'Check for Idle Winsocks. If found use it
If WSServer.UBound >= 2 Then
For io = 1 To WSServer.UBound
If WSServer(WSServer.UBound).State = 0 Then Can_use(WSServer.UBound) = True
If Can_use(WSServer.UBound) = True Then
WSServer(WSServer.UBound).Accept requestID
GoTo Connection_Made
Exit Sub
End If
Next io
End If
'If there's no idle WinSocks then add a new one
Load WSServer(WSServer.UBound + 1)
WSServer(WSServer.UBound).Accept requestID
Can_use(WSServer.UBound) = False
ServerConnectionsTxt.Text = Get_Connections 'Refresh how many connections there are
Connection_Made:
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
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 ?
Re: Winsock Stuck on connecting...
Yeah, i found the error after ripping my hair out
VB Code:
Dim Port_ As Variant
Dim IP_ As Variant
On Error GoTo Errors
If Len(IPTxt.Text) >= 1 Then IP_ = IPTxt.Text
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.