Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB Expert!

Join 244,283 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,140 people online right now. Registration is fast and FREE... Join Now!




winsock client and server problem

 
Reply to this topicStart new topic

winsock client and server problem

lukica18
17 Dec, 2008 - 12:47 PM
Post #1

New D.I.C Head
*

Joined: 17 Dec, 2008
Posts: 5

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:

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.

User is offlineProfile CardPM
+Quote Post


homemade-jam
RE: Winsock Client And Server Problem
17 Dec, 2008 - 12:57 PM
Post #2

eee Guru
Group Icon

Joined: 17 Mar, 2008
Posts: 1,243



Thanked: 4 times
Dream Kudos: 50
My Contributions
Could be all kinds of errors from ISP port blocking to routing issues.

Do you or your friend have a lan with a router? If so, port forwarding might need to be enabled. See here.

Also, there could be firewall issues at either end - try ping xxx.xx.xx.xxx in the command prompt - replace the x's with his/your ip address.

This post has been edited by homemade-jam: 17 Dec, 2008 - 12:58 PM
User is offlineProfile CardPM
+Quote Post

lukica18
RE: Winsock Client And Server Problem
17 Dec, 2008 - 01:17 PM
Post #3

New D.I.C Head
*

Joined: 17 Dec, 2008
Posts: 5

So you think its not in the code?

We both have routers xD. So i gues we'll both have to do port dorwarding.

And ping did not work, request timed out. So there is an firewall issue as well?
Its kinda late here so i ll continue testing tomorrow...
User is offlineProfile CardPM
+Quote Post

DeCompile
RE: Winsock Client And Server Problem
17 Dec, 2008 - 09:08 PM
Post #4

D.I.C Head
**

Joined: 20 Jul, 2008
Posts: 249



Thanked: 12 times
My Contributions
Although using port 80 is a bad idea for obvious reasons.

If you're both running routers then you will both need to port forward port 80 to your corresponding clients / server.
User is offlineProfile CardPM
+Quote Post

lukica18
RE: Winsock Client And Server Problem
18 Dec, 2008 - 07:08 AM
Post #5

New D.I.C Head
*

Joined: 17 Dec, 2008
Posts: 5

So which port would you suggest to be used for chat?
User is offlineProfile CardPM
+Quote Post

Rickster090
RE: Winsock Client And Server Problem
18 Dec, 2008 - 07:11 AM
Post #6

D.I.C Head
**

Joined: 10 Jan, 2008
Posts: 100


My Contributions
I'd check your firewall first then do the PING thing.
User is offlineProfile CardPM
+Quote Post

lukica18
RE: Winsock Client And Server Problem
18 Dec, 2008 - 11:36 AM
Post #7

New D.I.C Head
*

Joined: 17 Dec, 2008
Posts: 5

I ll test it with port forwarded and firewall configured next few days. I ll let you know the results. Thnx for help wink2.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 02:20PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month