Re: TCP/IP file transfer and a router
<aca04pds@shef.ac.uk> wrote in message
news:1177256895.141267.214920@e65g2000hsc.googlegroups.com...
Hi
I'm trying to create a Java program that can send a file from 1
Windows PC to another over a TCP/IP connection. As many people use
[wireless] routers, how can I create a TCP connection to PCs that are
connected to the internet via a router? The router has an IP and then
each PC connected to that has its own IP for their local network. How
would the router know which PC is the right one to send the data to?
If the LAN PCs are only running java.net.Socket (client sockets), you don't
need to do anything, since the NAT router keeps a table of requests, and
when the response comes back, the router automatically routes the response
to the proper requester using Network Address Translation (NAT).
For any PCs listening on java.net.ServerSocket, the router knows which PC to
send the data to using a router feature called "port forwarding". However,
you would have to assign a different port to each server behind the router,
because the router has a single address on the internet. Clients would have
to specify the host name and port in order to select a particular machine
behind the router.
Each PC on the LAN can listen on the same port, but you would need to
configure the router to publish each PC on a different port on the WAN.
By the way, this is not a Java problem, this is a router configuration
problem. Once you understand how NAT routers work, you can write the
solution in any language that supports TCP/IP (usually using Berkley
Sockets).