Winsock server and client problem
Hello.
I made a winsock server and client program. When i test it on my PC on localport(127.0.0.1) it works perfectly, but when i test it with my friend over internet it wont work. When i send a message it gets some error. No connectivity. So i guess we are not connected lol. So my question is. Is it possible that firewall is blocking client from connecting to a server or ther is a problem in code.
Here is the code for server
Code:
Private Sub Form_Load()
Winsock1.LocalPort = 80
Winsock1.Listen
End Sub
Private Sub TxtPoruka_KeyPress(KeyAscii As Integer)
On Error GoTo noconnection
If KeyAscii = 13 Then
Dim poruka1 As String
poruka1 = "[SERVER]: " + TxtPoruka
Winsock1.SendData poruka1
txtEkran.Text = txtEkran + poruka1 + vbCrLf
TxtPoruka.Text = ""
End If
noconnection:
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim PrimljenaPoruka As String
Winsock1.GetData PrimljenaPoruka
txtEkran.Text = txtEkran + PrimljenaPoruka + vbCrLf
End Sub
.... and here is for client
Code:
Private Sub mnuIzlaz_Click()
Unload Me
End Sub
Private Sub mnuSpojiSe_Click()
ip = InputBox("Unesite IP adresu racunala na koje se zelite spojiti", ip)
nadimak = InputBox("Unesite zeljeni nadimak", nadimak)
Winsock1.Close
Winsock1.Connect ip, 80
End Sub
Private Sub TxtPoruka_KeyPress(KeyAscii As Integer)
On Error GoTo noconnection
If KeyAscii = 13 Then
Dim poruka1 As String
poruka1 = "[" + nadimak + "]: " + TxtPoruka
Winsock1.SendData poruka1
txtEkran.Text = txtEkran + poruka1 + vbCrLf
TxtPoruka.Text = ""
noconnection:
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim poruka As String
Winsock1.GetData poruka
txtEkran.Text = txtEkran + poruka + vbCrLf
End Sub
thnx in advance.
Re: Winsock server and client problem
Quote:
Originally Posted by lukica18
So my question is. Is it possible that firewall is blocking client from connecting to a server or ther is a problem in code.
Most of the times the problem is the firewall and/or router.
In this case I see you are using port 80, so make sure that the firewall does not block it, and if you have a router, make sure that the port is forwarded to your computer (the one where you run the server program).
Re: Winsock server and client problem
Does your friend know what your IP address is? Are you on static or dynamic IP address. If dynamic then you will have a problem as it will be different each time you signon to the Internet. If static then make sure he known what it is and also make sure the port is correct. Otherwise CVMichael's post should be considered or it may be both problems.