Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cant connect to a remote pc not over LAN but over Internet [modified]

Cant connect to a remote pc not over LAN but over Internet [modified]

Scheduled Pinned Locked Moved C#
csharpiossysadminhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ayandelhi
    wrote on last edited by
    #1

    Hi!! I need some help... i cant connect to a a client running on a pc over net.. i got 2 programs one client and one server... running successfully when i give my local IP address... But when i change the local IP address to External IP address... it not working.. plz help me.. i want it to run over internet... Thanks in advance... client: 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....."); tcpclnt.Connect("120.56.168.186", 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 Server: `using System; using System.Text; using System.Net; using System.Net.Sockets; public class serv { public static void Main() { try { IPAddress ipAd = IPAddress.Parse("120.56.168.186"); //use local m/c IP address, and use the same in the client TcpListener myList=new TcpListener(ipAd,8001); 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`

    R B 2 Replies Last reply
    0
    • A ayandelhi

      Hi!! I need some help... i cant connect to a a client running on a pc over net.. i got 2 programs one client and one server... running successfully when i give my local IP address... But when i change the local IP address to External IP address... it not working.. plz help me.. i want it to run over internet... Thanks in advance... client: 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....."); tcpclnt.Connect("120.56.168.186", 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 Server: `using System; using System.Text; using System.Net; using System.Net.Sockets; public class serv { public static void Main() { try { IPAddress ipAd = IPAddress.Parse("120.56.168.186"); //use local m/c IP address, and use the same in the client TcpListener myList=new TcpListener(ipAd,8001); 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`

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Access to your remote PC is likely being blocked by a firewall. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      A 1 Reply Last reply
      0
      • A ayandelhi

        Hi!! I need some help... i cant connect to a a client running on a pc over net.. i got 2 programs one client and one server... running successfully when i give my local IP address... But when i change the local IP address to External IP address... it not working.. plz help me.. i want it to run over internet... Thanks in advance... client: 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....."); tcpclnt.Connect("120.56.168.186", 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 Server: `using System; using System.Text; using System.Net; using System.Net.Sockets; public class serv { public static void Main() { try { IPAddress ipAd = IPAddress.Parse("120.56.168.186"); //use local m/c IP address, and use the same in the client TcpListener myList=new TcpListener(ipAd,8001); 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`

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        ...and is the address of the remote PC really that PC's address and not the address of the modem?

        A 1 Reply Last reply
        0
        • R Ravi Bhavnani

          Access to your remote PC is likely being blocked by a firewall. /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          A Offline
          A Offline
          ayandelhi
          wrote on last edited by
          #4

          My client when runs first time.. a firewall exception will be added.. i'll do it myself..

          1 Reply Last reply
          0
          • B Bernhard Hiller

            ...and is the address of the remote PC really that PC's address and not the address of the modem?

            A Offline
            A Offline
            ayandelhi
            wrote on last edited by
            #5

            I dont know abt this...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups