c# - TcpClient- how to connect to an external IP address? -
i have been trying setup basic scenario tcpclient
connects tcplistener
on same machine, far works 127.0.0.1
, 192.168.x.y
. here code:
var server = new tcplistener(ipaddress.any, 51328); server.start(); var client = new tcpclient(); client.connectasync(ipaddress.parse("address whatismyip"), 51328); server.accepttcpclient(); // hangs indefinitely here console.readkey();
i got external address whatismyip i'm not sure if i'm doing correctly. incorrect procedure?
i assuming trying connect on internet? if connected via internet provider comcast have cable modem? sort of thing going need setup port forwarding on router.
the internet see's cable modem, requests internet go out cable modems ip, router able "route" packets , 192.168.x.x address on behalf, in order have 192.168 machine able listen , accept must tell router forward messages on port 51328 machine.
so code listen port 51328 using 192.168.x.xx address, setup router. test connect using public internet address assigned modem.
Comments
Post a Comment