Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to connect with a Server over the WAN using Client Server approach?
    primarykey
    data
    text
    <p>I am working on simple Client Server Application, it is just like a chat Messenger. I am using Client Server approach. My application works fine on LAN Local Area Network.but when it try to communicate to sever out side the LAN. Then there is no response to Client. while i know the server IP Address (through an external means ) which uses a broad band connection and resides on a WAN. i think i am unable to resolve the IP address, or proxy like problem occurs. Can anybody Help me out ? Regards ! Sm.Abdullah</p> <pre><code>// /* Server Program */ using System; using System.Text; using System.Net; using System.Net.Sockets; public class serv { public static void Main() { try { IPAddress ipAd = IPAddress.Parse("172.21.5.99"); // use local m/c IP address, and // use the same in the client /* Initializes the Listener */ TcpListener myList=new TcpListener(ipAd,8001); /* Start Listeneting at the specified port */ myList.Start(); Console.WriteLine("The server is running at port 8001..."); Console.WriteLine("The local End point is :" + myList.LocalEndpoint ); Console.WriteLine("Waiting for a connection....."); Socket s=myList.AcceptSocket(); Console.WriteLine("Connection accepted from " + s.RemoteEndPoint); byte[] b=new byte[100]; int k=s.Receive(b); Console.WriteLine("Recieved..."); for (int i=0;i&lt;k;i++) Console.Write(Convert.ToChar(b[i])); ASCIIEncoding asen=new ASCIIEncoding(); s.Send(asen.GetBytes("The string was recieved by the server.")); Console.WriteLine("\nSent Acknowledgement"); /* clean up */ s.Close(); myList.Stop(); } catch (Exception e) { Console.WriteLine("Error..... " + e.StackTrace); } } } --------------------------------------------------------------------------- /* Client Program */ using System; using System.IO; using System.Net; using System.Text; using System.Net.Sockets; public class clnt { public static void Main() { try { TcpClient tcpclnt = new TcpClient(); Console.WriteLine("Connecting....."); // here is local ip.. // if i replace it with WAN IP it does not communicate. tcpclnt.Connect("172.21.5.99",8001); // use the ipaddress as in the server program Console.WriteLine("Connected"); Console.Write("Enter the string to be transmitted : "); String str=Console.ReadLine(); Stream stm = tcpclnt.GetStream(); ASCIIEncoding asen= new ASCIIEncoding(); byte[] ba=asen.GetBytes(str); Console.WriteLine("Transmitting....."); stm.Write(ba,0,ba.Length); byte[] bb=new byte[100]; int k=stm.Read(bb,0,100); for (int i=0;i&lt;k;i++) Console.Write(Convert.ToChar(bb[i])); tcpclnt.Close(); } catch (Exception e) { Console.WriteLine("Error..... " + e.StackTrace); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload