Ben erasmus

Ben erasmus

  • NA
  • 4
  • 2.1k

Socket - Gobal IP address

Mar 24 2014 10:42 AM
Im trying to connect to a pc using the gobal IP address. If use the local IP address my code works fine. As soon as I start to use the gobal ip address it timesout.
 
 
Can someone help me please.
 
My local IP address is 192.168.1.101
and gobal IP is: 41.132.43.220
 
Here is my code:
 
TcpClient socketForServer ;
bool status = true ;
//41.135.31.49
//192.168.1.105
socketForServer = new TcpClient("192.168.1.101",8100) ;
Console.WriteLine("Connected to Server") ;

NetworkStream networkStream = socketForServer.GetStream() ;
StreamReader streamreader = new StreamReader(networkStream) ;
StreamWriter streamwriter = new StreamWriter(networkStream) ;

string clientmessage="" ;
string servermessage="" ;
while(status)
{
Console.Write("Client:") ;
clientmessage = Console.ReadLine() ;

streamwriter.WriteLine(clientmessage) ;
streamwriter.Flush() ;
servermessage = streamreader.ReadLine() ;
Console.WriteLine("Server:"+servermessage) ;

}
streamreader.Close() ;
networkStream.Close() ;
streamwriter.Close() ;