Click to See Complete Forum and Search --> : [RESOLVED] vb winsock server/client error
MeTTa@
Feb 17th, 2006, 01:03 AM
I used an online tutorial to create this, I tested it over my network, works fine. When i test it with a friend i get a error, i have a feeling its with the ip gathering. Have a look, Thanks,
___
Dan
the182guy
Feb 17th, 2006, 11:17 AM
This problem can occur if the server app machine is using a router to connect to the internet, if this is the case for you, you ned to forward the listening port(s) on the router to your network IP. So when the client app connects, it will try to connect to the router, which will then pass the connection on to your network IP
MeTTa@
Feb 17th, 2006, 01:14 PM
Ok, makes sense, but how would i do that?
the182guy
Feb 17th, 2006, 01:45 PM
Your router will have some sort of control panel, usually they are a HTML page based (but not online, only available to your network so its an 'intranet' page). Take a look at the instruction manual for the router it will tell you how to get to the control panel. if you dont have any instruction booklets, search for the model and manufactuer on google, and you will loads of info how to do things with it.
CVMichael
Feb 17th, 2006, 01:45 PM
Well, at least you added the winsock control in the Components tab...
Though this does not look like a client/server program to me:
Private Sub Timer1_Timer()
Label1.Caption = Time
End Sub
Are you sure you posted the right project ?
MeTTa@
Feb 17th, 2006, 01:53 PM
Im most likely sure lol, im not at home at the moment, but i wouldnt be surprised if it wasnt. Does it look like a chat layout?
the182guy
Feb 17th, 2006, 01:56 PM
You said you get an error.....what error do you get? When the error occurs is it a vb runtime error? If it is, you can click the debug button and find out which line its on, so if you could tell us the line and the error description that would be great
MeTTa@
Feb 17th, 2006, 01:59 PM
Pretty sure it was a runtime error, and if i remember right it was on a line like
"winsock.sendata" or something... Il be home in 2 hours to confirm.
My friend was saying it could be the port being closed, if so he said i should change it to 80.*always open*
the182guy
Feb 17th, 2006, 02:13 PM
Yes you could connect to the server machine on port 80, but why? Unless the server is listening on port 80, nothing will be there to receive/process the data.
If you change the listen port to 80 it wont solve your problem, no other app will be closing the port, if the port is being closed - in other words the connection has ended, it will be either the client, or the server which closed the connection, unless the client or server lost connection to the internet.
I think the error you are getting is 'wrong connection state for the requested transaction' (off the top of my head), this error occurs when you try to send data if the socket is not connected, it may have been connected before but the current state is 'sckNotConnected'.
When you send data you could use:
If Winsock1.State = sckConnected Then
Winsock1.SendData "hello"
Else
Msgbox "The socket is not connected"
End if
this wont solve your problem but what it will do is show a 'friendlyer' message box to tell the user that the connection is not established so you cant send any data, instead of the horrid vb runtime error.
Anyway as soon as you upload the project I can check it to see if it is a code problem, or it is your router that needs the ports forwarding. But since the app works fine over a network, and not over the internet, it makes it likely that it is infact the router thats causing the problem.
I think the problem is when the client attempts connection, its failing because the router is ignoring the connection, instead of forwarding it to your server app
MeTTa@
Feb 17th, 2006, 02:25 PM
It is uploaded, in my first post.
the182guy
Feb 17th, 2006, 02:41 PM
It is uploaded, in my first post.
Oh sorry I thought someone said it was the wrong project.
Anyway ive checked it and theres nothing hugely wrong with the code, it works fine here. So im pretty sure the problem is with the router.
If your computer doesnt use a router and your friends computer does, then try using your computer as the Listen (server), and your friend as the client (the one which uses the 'connect' button...
Just a couple of tips....
When you add the data to the textbox thats received it looks like...
[Chris]Hey[Bob]Hiya[Chris]Hows you? etc
If you wanted each message on a new line you could put a new line at the end of your incoming message, so change this line of code:
txtIn = txtIn & incoming
To...txtIn = txtIn & incoming & vbCrLf
This will add a new line character onto each message so the chat will be like
[Chris]Hey
[Bob]Hi...
The other thing i noticed was you dont having any code in the Winsock_Close event. This event fires if the remote computer which you are connected with decides to end the connection. It is basically fired when the connection is lost....so it could happen if your friends computer loses its connection to the internet.
So in the Winsock_Close event, you could make a message show in the textbox to tell you that the connection has been lost so the close sub would look like...
Private Sub wsChat_Close()
txtIn.Text = txtIn.Text & "----Connection closed by remote side----" & vbCrLf
wsChat.Close 'It is good practice to close the socket when the close event is fired
End Sub
MeTTa@
Feb 17th, 2006, 02:53 PM
Ok, i saw those bugs :P, nothing really important, but we both have routers, and we cant get it to work. I can make it work over a network, but not over the net.
CVMichael
Feb 17th, 2006, 03:02 PM
Oh sorry I thought someone said it was the wrong project.
Anyway ive checked it and theres nothing hugely wrong with the code, it works fine here.
OK... that is weird :confused:
I just downloaded the attachment in the first post, and I see the same thing !
A project with a label on it, and a timer.
The timer event just updates the label with the current time...
That's it ! 3 lines of code in the whole project....
What is going on ??? is there an attachment somewhere else ?
MeTTa@
Feb 17th, 2006, 03:12 PM
LOL! No idea... But it is in fact my project(not what you see). And congrats on you 2,500th post! :cool:
CVMichael
Feb 17th, 2006, 03:23 PM
LOL! No idea... But it is in fact my project(not what you see).
I downloaded the attachment in the first post, and I attached it in this post
See it for yourself...
I think this is the weirdest thing ever hapened on vbforums... how can I see one attachment, and everyone else see another attachment ? that is so weird :confused:
And congrats on you 2,500th post! :cool:
Thanks, I did not even notice...
Edit
Removed attachment...
the182guy
Feb 17th, 2006, 03:27 PM
The ZIP file in his orginal post is fine, it holds the right vb project, ive downloaded it in checked it........@michael you must be viewing a different app, instead of eztracting the zip, run it from its current location and just run the form file from in the zip
the182guy
Feb 17th, 2006, 03:30 PM
Ok, i saw those bugs :P, nothing really important, but we both have routers, and we cant get it to work. I can make it work over a network, but not over the net.
Then im 100% sure it is the port forwarding. Whoever is going to be the server for the chat (the one which listens) needs to have the port forwarding set up on port 1234 (i think that was your port? cant remember).
Put the name of your router along with 'port forwarding' into google and there will be pages telling you how to do it.
CVMichael
Feb 17th, 2006, 03:38 PM
What the ...... I did not go insane overnight, I'm sure !
What is going on here ?
Here, I attached a screen shot of the first thread... SEE ! there is one attachment, named "chit.zip", and it is 2.3 KBytes.... It's just a project with 3 lines in it !!!
Edit
I removed the screen shot, not needed anymore...
MartinLiss
Feb 17th, 2006, 03:52 PM
The problem seems to be that the vbp file and the form included are unrelated. The vbp is looking for Form1 but in ..\..\..\..\Program Files\Microsoft Visual Studio\VB98\Form1.frm rather than the chit folder.
the182guy
Feb 17th, 2006, 03:54 PM
Really, the project in the first thread is a winsock chat program! Should I call the guys in the white jackets out for you? heehee - just kidding mate! extract the zip to a new folder somewhere then run the vb app from there
the182guy
Feb 17th, 2006, 03:55 PM
You will get an error when it loads....then you just need to remove any current forms, and add the form which you extracted from the zip
CVMichael
Feb 17th, 2006, 03:56 PM
The problem seems to be that the vbp file and the form included are unrelated. The vbp is looking for Form1 but in ..\..\..\..\Program Files\Microsoft Visual Studio\VB98\Form1.frm rather than the chit folder.
Your right !!
And guess what !
In the folder "Program Files\Microsoft Visual Studio\VB98\" I happen to have a Form1.frm with that code in it !! :D :D
So in my case it was pointing to a valid location !
penagate
Feb 17th, 2006, 03:57 PM
The problem seems to be that the vbp file and the form included are unrelated. The vbp is looking for Form1 but in ..\..\..\..\Program Files\Microsoft Visual Studio\VB98\Form1.frm rather than the chit folder.
Oh, that would explain it, Michael must already have a Form1.frm in that folder.
Edit: So he does :)
CVMichael
Feb 17th, 2006, 03:58 PM
Ow, THANK GOD !!!
I thought I went crazy !
Oh... I feel so much better now
the182guy
Feb 17th, 2006, 04:05 PM
Ow, THANK GOD !!!
I thought I went crazy !
Oh... I feel so much better now
I'm glad we have that cleared up :)
@thread starter...have you forwarded that port yet!? :rolleyes:
MeTTa@
Feb 17th, 2006, 04:55 PM
I dont think i want to go that route, i want this to be user friendly with any network.
CVMichael
Feb 17th, 2006, 05:10 PM
I dont think i want to go that route, i want this to be user friendly with any network.
You won't be able too... even programs like MSN use a centralized server (where everyone connects, and routes the messages) that has a port open through the firewall/router. There is no way around it.
the182guy
Feb 17th, 2006, 05:12 PM
It will work fine from a network computer to another network computer, but if you have a router and your trying to be the server unless you forward the port on the router, the connection attempt will never get through the router, the router will just drop the connection, its never going to get to your network computer which has the vb app. Everything from the internet has to come through the router.
Its nothing to do with vb programming or winsock its a hardware issue
MeTTa@
Feb 17th, 2006, 05:39 PM
what if i have a dirrect connection to my modem, will that fix the problem?
CVMichael
Feb 17th, 2006, 05:45 PM
what if i have a dirrect connection to my modem, will that fix the problem?
You mean if you disable the firewall, and router, then yes, there should be no problem connecting.
the182guy
Feb 17th, 2006, 07:07 PM
You mean if you disable the firewall, and router, then yes, there should be no problem connecting.
I agree with Michael - just make sure that you are the server (the one which listens).
The reason it fixes the problem, by having a connection through a modem is the modem is your internet gateway, so therefore any attempted connections are directed to the computer, where your vb app will be waiting
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.