in reply to Sending Socket peer to peer

It's seems you misunderstood what LocalAddr is. LocalAddr is the address that sender should use as source address, you can specify it if PC1 has several IP and you want to use one of them. PeerAddr should be the address of PC2, what do you mean by "IP of the network of PC2". If PC2 has local IP, you can't directly connect to it over the internet. You should use SOCKS or some sort of NAT on router to be able to connect to PC2 in this case. What kind of router do you use?

Replies are listed 'Best First'.
Re^2: Sending Socket peer to peer
by eye (Chaplain) on Dec 07, 2008 at 17:23 UTC
    Building on what zwon said...

    The LocalAddr is the source address; the PeerAddr is the destination address. If PC2 has a private address (falling in one of these ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16; aka an RFC1918 address), then it cannot be reached directly from outside its local network. In that case, PeerAddr needs to be the address of the router for PC2's network. Additionally, you must create a mechanism for traffic arriving on port 7070 of the router to be forwarded to port 7070 on PC2.

    On most appliance routers for the home (e.g. Linksys WRT54G), this is called port forwarding. There is usually a configuration page for this in the router setup (on some routers, this may be hidden behind an "advanced" setup tab).

    On other routers, port forwarding is usually called DNAT (destination network address translation) because the router will rewrite the destination address of forwarded packets with the private address for PC2 (which is reachable from its router).

    Here, we see a big limitation of NAT (network address translation). Only one host behind a router can receive traffic to port 7070. It is possible to map other ports (e.g., 7071) to port 7070 on host PC3, but the protocol must allow for PC1 to send to PC3 via a port other than 7070.

    If these limitations are too limiting, another approach is to create a VPN (virtual private network; e.g., openvpn, IPsec). This could be used to create a direct path from PC1 to PC2 and PC3, though there are important security implications to this type of approach that far exceed the scope of this post.

      Thank you verry much, this is really helpfull post!