Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

ghost's Avatar
0 0

It took a while to swallow my pride and ask this, since i consider myself entirely fluent in vb, but anyway, how long should it take for a winsock to connect? I'm sure the code is right, and i'm testing it on my own computers, but its not connecting. Any ideas?


ghost's Avatar
0 0

if the code is entirly correct, and both the client and the server are running. then instantly really

are you using SIN connection or Direct?

heres an example of direct connection

client:

Private Sub cmdconnect_Click()
On Error Resume Next
Winsock1.Connect "127.0.0.1", "6080"
End Sub

server:

Private Sub Form_Load()
    Timer1.Interval = "1000"
    Timer1.Enabled = True
    Winsock1.Close
    Winsock1.LocalPort = "6080"
    Winsock1.Listen
End Sub

Private Sub Timer1_Timer()
If Winsock1.State <> 7 Then
    Winsock1.Close
    Winsock1.Listen
Else
    Exit Sub
End If
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Close
    Winsock1.Accept requestID
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    Winsock1.Close
    Winsock1.Listen
End Sub

works for me, you should learn how to split data then u shuld b able to make a wikid program


ghost's Avatar
0 0

The only thing i don't have out of that is the timer repeatedly trying to connect. Other then that, its all there. Yet it still doesn't work. =\


ghost's Avatar
0 0

hmm can you post your code please, ill figure out whats wrong with it


ghost's Avatar
0 0

post your code please, ill figure out whats wrong with it ;)


ghost's Avatar
0 0

Here is all the connection stuff

Server:

Form 
Winsock1.LocalPort = 80
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
On Error Resume Next
If Winsock1.State <> sckClosed Then Winsock1.Close 
Winsock1.Accept requestID ```

Client:
```markup
Private Sub Label2_Click()
Winsock1.Close
Dim host As String
Dim port As String

host = Text1.Text
port = "80"


If host = "" Or host = "This is where you put the Target IP" Then
MsgBox "Please enter a host IP", vbDefaultButton1, "Enter Host"
End If
Winsock1.Connect host, port
End Sub```

I think thats all the connection related stuff. So, ideas?

ghost's Avatar
0 0

hmm that seems right to me


ghost's Avatar
0 0

Yeah, it seemed right to me too. I know both computers have winsock, since I'm testing it on my own comps. Is it possible its something with my firewall?


ghost's Avatar
0 0

sorry for double post.