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. Problem Occured - IP address

Problem Occured - IP address

Scheduled Pinned Locked Moved C#
sysadminhelpquestioncsharptesting
4 Posts 2 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.
  • J Offline
    J Offline
    Jijo BP
    wrote on last edited by
    #1

    G’Day, Actually I have a problem with my network program. Can you help me ?. Actually my laptop is in a WLAN. Means my IP address is local to this LAN. I am developing a client / server software. In this I want to communicate to a P.C in a different network. Eg. My loacl IP is 192.168.0.15 and the other P.C (which I want to communicate to) is 192.168.1.23. But these IPs are there local IPs. The problem comes in the following code. private void Form1_Load(object sender, System.EventArgs e) { Thread mythread = new Thread(new ThreadStart(serverThread)); mythread.Start(); } public void serverThread() { UdpClient udpClient = new UdpClient(999); while(true) { IPEndPoint RemoteEndPoint = new IPEndPoint(IPAddress.Any,0); // listing for reply Byte[] receiveBytes = udpClient.Receive(ref RemoteEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); } } private void btnReplay_Click(object sender, System.EventArgs e) { string ips = “192.168.0.1.23” ; UdpClient udpClient = new UdpClient(); udpClient.Connect(ips,999); Byte[] sendBytes = Encoding.ASCII.GetBytes(“Hi I am testing”); // sending reply udpClient.Send(sendBytes,sendBytes.Length); } The problem is 1. I want to specify the IP address of the destination machine string ips = “192.168.0.23” ; Here I iam specifying the local Ip of the machine which is in a different network. How can I communicate to the destination machine ? How NAT works ? Can you guide me in a proper way using c# ? Thanks in advance Cheers

    P 1 Reply Last reply
    0
    • J Jijo BP

      G’Day, Actually I have a problem with my network program. Can you help me ?. Actually my laptop is in a WLAN. Means my IP address is local to this LAN. I am developing a client / server software. In this I want to communicate to a P.C in a different network. Eg. My loacl IP is 192.168.0.15 and the other P.C (which I want to communicate to) is 192.168.1.23. But these IPs are there local IPs. The problem comes in the following code. private void Form1_Load(object sender, System.EventArgs e) { Thread mythread = new Thread(new ThreadStart(serverThread)); mythread.Start(); } public void serverThread() { UdpClient udpClient = new UdpClient(999); while(true) { IPEndPoint RemoteEndPoint = new IPEndPoint(IPAddress.Any,0); // listing for reply Byte[] receiveBytes = udpClient.Receive(ref RemoteEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); } } private void btnReplay_Click(object sender, System.EventArgs e) { string ips = “192.168.0.1.23” ; UdpClient udpClient = new UdpClient(); udpClient.Connect(ips,999); Byte[] sendBytes = Encoding.ASCII.GetBytes(“Hi I am testing”); // sending reply udpClient.Send(sendBytes,sendBytes.Length); } The problem is 1. I want to specify the IP address of the destination machine string ips = “192.168.0.23” ; Here I iam specifying the local Ip of the machine which is in a different network. How can I communicate to the destination machine ? How NAT works ? Can you guide me in a proper way using c# ? Thanks in advance Cheers

      P Offline
      P Offline
      Phil C
      wrote on last edited by
      #2

      Not sure if this is a direct answer to your problem or not, but are you sure your machine can even see the other one with the way the IP addresses are set up? In other words, what are the subnet masks on the machine. If either one is set to the standard 255.255.255.0 these two machines will not be able to see one another regardless of how your program is coded becaues the network mask blocks/prevents all IP traffic except on your local network. Quick way to test it is to pull up a command prompt on your machine then type: ping 192.168.1.23...if you get a reply then all should be ok. By the way, as I was checking back in your message to make sure I typed the right IP address, I notice your program reads: string ips = “192.168.0.23” ; Shouldn't that be "192.168.1.23";???????????????

      J 1 Reply Last reply
      0
      • P Phil C

        Not sure if this is a direct answer to your problem or not, but are you sure your machine can even see the other one with the way the IP addresses are set up? In other words, what are the subnet masks on the machine. If either one is set to the standard 255.255.255.0 these two machines will not be able to see one another regardless of how your program is coded becaues the network mask blocks/prevents all IP traffic except on your local network. Quick way to test it is to pull up a command prompt on your machine then type: ping 192.168.1.23...if you get a reply then all should be ok. By the way, as I was checking back in your message to make sure I typed the right IP address, I notice your program reads: string ips = “192.168.0.23” ; Shouldn't that be "192.168.1.23";???????????????

        J Offline
        J Offline
        Jijo BP
        wrote on last edited by
        #3

        Thank You. If I ping to 192.168.1.23 . It shows the message " Request timed out". Because it is the local IP of another network. I dont know how to communicate to a client which is in another network ,if I have the global IP of that network. Thank you for your advice Cheers Jijo

        P 1 Reply Last reply
        0
        • J Jijo BP

          Thank You. If I ping to 192.168.1.23 . It shows the message " Request timed out". Because it is the local IP of another network. I dont know how to communicate to a client which is in another network ,if I have the global IP of that network. Thank you for your advice Cheers Jijo

          P Offline
          P Offline
          Phil C
          wrote on last edited by
          #4

          Yup, I had a feeling it wsa something along those lines. You'll probably need more detailed info on the network configuration. For instance is port forwarding enabled, firewalls, etc. I can think of several things that will prevent these two machines from establishing a UDP connection. You can start by finding out your public IP address by using something like: http://www.whatismyipaddress.com Maybe if you run it on both machines you can get a start, but since your machines are probably set to dynamic IP addresses it's going to change each time you reboot either machine. All I can advise at this point is to use the ping command as you try various settings and addresses. A lot easier than changing your program and re-compiling to find out if the two machines are able to talk to see each other.

          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