Results 1 to 31 of 31

Thread: [RESOLVED] vb winsock server/client error

  1. #1

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Resolved [RESOLVED] vb winsock server/client error

    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
    Attached Files Attached Files

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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
    Chris

  3. #3

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    Ok, makes sense, but how would i do that?

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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.
    Chris

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    Well, at least you added the winsock control in the Components tab...
    Though this does not look like a client/server program to me:
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Label1.Caption = Time
    3. End Sub

    Are you sure you posted the right project ?

  6. #6

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    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?

  7. #7
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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
    Chris

  8. #8

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    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*

  9. #9
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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:
    VB Code:
    1. If Winsock1.State = sckConnected Then
    2.      Winsock1.SendData "hello"
    3. Else
    4.      Msgbox "The socket is not connected"
    5. 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
    Chris

  10. #10

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    It is uploaded, in my first post.

  11. #11
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    Quote Originally Posted by MeTTa@
    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:
    VB Code:
    1. txtIn = txtIn & incoming
    To...
    VB Code:
    1. 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...

    VB Code:
    1. Private Sub wsChat_Close()
    2. txtIn.Text = txtIn.Text & "----Connection closed by remote side----" & vbCrLf
    3. wsChat.Close 'It is good practice to close the socket when the close event is fired
    4. End Sub
    Chris

  12. #12

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    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.

  13. #13
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    Quote Originally Posted by the182guy
    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
    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 ?

  14. #14

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    LOL! No idea... But it is in fact my project(not what you see). And congrats on you 2,500th post!
    Last edited by MeTTa@; Feb 17th, 2006 at 04:17 PM.

  15. #15
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    Quote Originally Posted by MeTTa@
    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

    Quote Originally Posted by MeTTa@
    And congrats on you 2,500th post!
    Thanks, I did not even notice...

    Edit
    Removed attachment...
    Last edited by CVMichael; Feb 17th, 2006 at 05:26 PM.

  16. #16
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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
    Chris

  17. #17
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    Quote Originally Posted by MeTTa@
    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.
    Chris

  18. #18
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    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...
    Last edited by CVMichael; Feb 17th, 2006 at 05:05 PM.

  19. #19
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: vb winsock server/client error

    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.

  20. #20
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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
    Chris

  21. #21
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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
    Chris

  22. #22
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    Quote Originally Posted by MartinLiss
    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 !!

    So in my case it was pointing to a valid location !

  23. #23
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: vb winsock server/client error

    Quote Originally Posted by MartinLiss
    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

  24. #24
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    Ow, THANK GOD !!!

    I thought I went crazy !

    Oh... I feel so much better now

  25. #25
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    Quote Originally Posted by CVMichael
    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!?
    Chris

  26. #26

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    I dont think i want to go that route, i want this to be user friendly with any network.

  27. #27
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    Quote Originally Posted by MeTTa@
    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.

  28. #28
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    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
    Chris

  29. #29

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: vb winsock server/client error

    what if i have a dirrect connection to my modem, will that fix the problem?

  30. #30
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: vb winsock server/client error

    Quote Originally Posted by MeTTa@
    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.

  31. #31
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: vb winsock server/client error

    Quote Originally Posted by CVMichael
    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
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width