Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Port forwarding for socket programming

  • 28-11-2011 9:42pm
    #1
    Registered Users, Registered Users 2 Posts: 377 ✭✭


    Im messing about with socket programming and I want to forward ports to my pc.

    So in my 'network', there are the following machines -
    192.168.1.11 - My pc
    192.168.1.13 - My mother's laptop

    Say I want to open a port on my pc, say port number 55555. Looking at my netopia 3347 modem I have the following options -

    Service Name:
    Global Port Range: [ ] - [ ]
    Base Host Port: [ ]
    Protocol - [TCP] or [UDP]

    1. It doesnt let me specify which machine to forward to so does that mean any connections coming in on port 55555 will get sent to all the machines on my network? That doesn't seem to make much sense as if both my pc and my mothers laptop were running different services on por 55555 how would the router send the request to the desired port....??

    2. How do Global port range and base host port work? If set a global port range to say, 50000-51000 and base host port to 55555 does that mean all traffic coming in on the range of global ports will get sent to the single port 55555?


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    If you are doing everything on the private network (192.168.xxx.xxx/24), then your router won't be doing anything with the router.

    Port forwarding is only for NAT when you are trying to open ports on a computer for users outside of your network on the internet. Or on a different subnet to what you are on.
    The router is only used when you want to send packets from your own network to another network. (Hence routing). When you are on the same network, your router won't be used. A direct connection will be made between your two PCs on a MAC/Ethernet level.

    It should be only a matter of firewalls on your PCs that needs to be configured.

    I hope I haven't made the wrong assumption of what you are trying to achieve here.


  • Registered Users, Registered Users 2 Posts: 377 ✭✭irishdude11


    Webmonkey wrote: »
    If you are doing everything on the private network (192.168.xxx.xxx/24), then your router won't be doing anything with the router.

    Port forwarding is only for NAT when you are trying to open ports on a computer for users outside of your network on the internet. Or on a different subnet to what you are on.
    The router is only used when you want to send packets from your own network to another network. (Hence routing). When you are on the same network, your router won't be used. A direct connection will be made between your two PCs on a MAC/Ethernet level.

    It should be only a matter of firewalls on your PCs that needs to be configured.

    I hope I haven't made the wrong assumption of what you are trying to achieve here.

    Ok ty for that info, Im trying to get as solid an understanding as I can of how networking works.

    I am running into some problems now though. I have got a client and server up and running over my local network but I cant get them to connect over the internet.

    I am running the asynchronous client and server examples from MSDN

    Server - http://msdn.microsoft.com/en-us/library/fx6588te.aspx
    Client - http://msdn.microsoft.com/en-us/library/bew39x2a.aspx

    Connection using local address - This works fine
    1. Im using a laptop as a client (192.168.1.13), and my pc as the server (192.168.1.11).
    2. I set my server to use a port number of 54321.
    3. When I connect from the client using the server ip address of 192.168.1.11 and port of 54321 the connection works fine and I get text appearing on the console windows of both the server and client.


    Connecting over the internet
    - This is not working
    1. First I disable windows firewall. (I just want to take the firewall out of the equation til I can actually get the connection to work)
    2. Then I log into my router and create the following port forward service -
    Service Name: AsyncServerTest
    Protocol: TCP
    Global Port Range
    : 54321 - 54321
    Base Host Port: 54321
    3. I click submit and on the next page I set my PC as the Host Device for this service.
    4. Then I try and connect the client to the server over the internet using my internet address of 86.42.abc.xyz and port number of 54321.
    5. The client hangs for about ten seconds when I call BeginConnect() and then it throws up an exception - "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because host has failed to respond 86.42.abc.xyz."
    6. Simultaneously I get an exception in my server program on the BeginReceive() method - An existing connection was forcibly closed by the remote host.
    7. So at least I know the client and server are definitly making contact.

    Surely this should be working though, all I have changed is the IP address from a local one to an internet one, and I have my modem/router forwarding traffic to port 54321 to my pc. Ive been debugging for hours here, I cant see why these exceptions are occurring. Anyone got any ideas?


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    So it would appear to me that your port forwarding is correct and you are getting a connection started from the client to the server. But then the client seems to have a problem continuing the 3way handshake.

    Have you disabled the firewall on both sides? Client and server.


  • Registered Users, Registered Users 2 Posts: 377 ✭✭irishdude11


    I disabled the firewall on the client and tried again with no luck. A simultaneous exception occurrs on both machines.


  • Registered Users, Registered Users 2 Posts: 377 ✭✭irishdude11


    Figured it out. There is a firewall on the router too, when I disable this or set it to low the connection gets made. Seems a bit stupid that when I select a port to forward it doesnt automatically bypass the firewall.


  • Advertisement
Advertisement