#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Socket programming - port problem


    hi all.

    i wrote two simple programmes which establish connection with each other : a server and a client.they seem to work well when i run them both on my pc by simply passing 127.0.0.1 or localhost and server's well-known port to client.(without manually opening any ports in my dsl router )

    but when i try to do the same thing with one of my friends by running server on his pc, he needs to open the port specified in server's source codes manually in his dsl-router, othewise i get a "connection refused error".

    And what is more interesting and frustrating is that when i run the server and he runs the client he can connect me easily although i do not forward the specified port in my router.

    actually i tried this with two fellas and the results were the same.

    FYI :
    - every pc have windows firewall and before running server, firewalls are authorized to allow the server to run.

    -we are not in same network.

    How could I overcome this situation?
    Do I need to open a port in router with C codes?
    Is such a thing possible?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Davie, FL
    Posts
    461
    Rep Power
    180
    Originally Posted by arctic.blue
    hi all.

    i wrote two simple programmes which establish connection with each other : a server and a client.they seem to work well when i run them both on my pc by simply passing 127.0.0.1 or localhost and server's well-known port to client.(without manually opening any ports in my dsl router )

    but when i try to do the same thing with one of my friends by running server on his pc, he needs to open the port specified in server's source codes manually in his dsl-router, othewise i get a "connection refused error".

    And what is more interesting and frustrating is that when i run the server and he runs the client he can connect me easily although i do not forward the specified port in my router.

    actually i tried this with two fellas and the results were the same.

    FYI :
    - every pc have windows firewall and before running server, firewalls are authorized to allow the server to run.

    -we are not in same network.

    How could I overcome this situation?
    Do I need to open a port in router with C codes?
    Is such a thing possible?
    There's a big difference sending stuff out on a seperate port, and allowing connections to come in on those ports. so, chances are, if the person/company wants to run the server, they're going to need to open the ports in their router. As as far as opening the ports using c-code, it would depend on if that router had an ability to take commands remotely. But I would say, off-handed, that it cant be guaranteed to work on all routers.

    So, to answer your question, no, I dont see a way around what you are trying to do. Unless you switch to a port thats not normally blocked by routers.

    Comments on this post

    • arctic.blue agrees : thanks
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0
    First of all, thanks for your response.

    But I think we have made some progress here..My pc had been accepting all the connections because DMZ Host of my router was set to my local IPAdress and was activated.So When I deactivated it my pc begun not to accept connections from outside neither.

    Now the question is how could I achieve this communication between two remote PCs just with codes - wtihout doing something manually?

    Thanks.
  6. #4
  7. Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jun 2005
    Posts
    5,929
    Rep Power
    4855
    The intended nature (often ****ed over by user choice) of the client/server relationship is that clients send requests and servers send responses. The server should not normally be able to initiate a transaction.

    A system can be configured so that a client will respond to a server. This is mostly undesired. When you want to buy shoes, you normally want to go to the shoe store. You don't want shoe salesmen, Fuller Brush salesmen, and Jehovah's Witnesses coming to your door unilaterally. Well, most of us don't. You want to go to them, or you want to schedule a prior appointment.

    The reason that a router is a good line of defense is that, by default, it stops the house-to-house salesmen at the sidewalk. You can defeat that, if you like, but it takes some router adjustments. You don't get that same facility in your PC, generally. All you have to do is say 'Yes' to a bargain buddy or a toolbar, and you're screwed without being kissed.

    Write a thank-you note to your router, and learn how to subvert its natural operating modes, if you must.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0
    Originally Posted by sizablegrin
    The intended nature (often ****ed over by user choice) of the client/server relationship is that clients send requests and servers send responses. The server should not normally be able to initiate a transaction.

    A system can be configured so that a client will respond to a server. This is mostly undesired. When you want to buy shoes, you normally want to go to the shoe store. You don't want shoe salesmen, Fuller Brush salesmen, and Jehovah's Witnesses coming to your door unilaterally. Well, most of us don't. You want to go to them, or you want to schedule a prior appointment.

    The reason that a router is a good line of defense is that, by default, it stops the house-to-house salesmen at the sidewalk. You can defeat that, if you like, but it takes some router adjustments. You don't get that same facility in your PC, generally. All you have to do is say 'Yes' to a bargain buddy or a toolbar, and you're screwed without being kissed.

    Write a thank-you note to your router, and learn how to subvert its natural operating modes, if you must.
    Thank you also but I think you got me wrong.My server does not try to connect to client.DMZ host(server side) prevents the client from connecting to the server.And that is what I cannot figure out now.
  10. #6
  11. Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jun 2005
    Posts
    5,929
    Rep Power
    4855
    but when i try to do the same thing with one of my friends by running server on his pc, he needs to open the port specified in server's source codes manually in his dsl-router, othewise i get a "connection refused error".
    Have you set it up for a non-traditional port, or has your friend set his router for extremely tight control?
  12. #7
  13. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,782
    Rep Power
    4301
    Originally Posted by arctic.blue
    Thank you also but I think you got me wrong.My server does not try to connect to client.DMZ host(server side) prevents the client from connecting to the server.And that is what I cannot figure out now.
    Yes, that's exactly what sizeable grin was talking about though. It doesn't matter if you're a server or a client. You don't want people coming in and banging on ports on your machine, unless you've specifically allowed it by cutting a hole in your firewall.

    Let's say you've unwittingly installed a program that also contained a virus written by a mail spammer. Generally, these lads love to leave a daemon running on your machine that runs on a specific port. Then, they send commands to the daemon and ask it to forward email for them. This way, the spam email appears to originate from your machine, not theirs. With a DMZ in place, even if the daemon is running, at least they won't be able to contact the daemon, because the DMZ will block attempts to connect to the port.

    Another infamous example was an IIS bug that I still keep getting hits for (even though I don't run IIS). A lot of people would run the IIS service on their computer without knowing what it was, or bothering to keep up with patches. Result: Someone found an exploit and used it to compromise boxes. The problem got so bad that ISPs generally block requests to port 80 on any home network customers.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0
    Scorpions4ever :

    Thanks for the information :)

    sizablegrin:

    Sorry for my previous reply.It seems that I got you wrong(most likely because of my poor english :) )

    As to your question, I have tried ports from all kinds of port ranges so far : 1-1023 , 1024 - 49151, and 49152 - 65535.

    But same result.

IMN logo majestic logo threadwatch logo seochat tools logo