help with internet connection

edited February 2019 in Library Questions

hi.I am trying to communicate 2 pc via internet.when i run basic SERVER and CLIENT example with local ip-127.0.0.1 in the same pc it works.but when i run client example from my work pc it doesnt work.i use my home ip in CLIENT example.it doesnt work.please help me

/**************SERVER*******************************/

import processing.net.*;
Server myServer;
int val = 0;

void setup() {
  size(200, 200);
  // Starts a myServer on port 5204
  myServer = new Server(this, 5204); 
}

void draw() {
  val = (val + 1) % 255;
  background(val);
  myServer.write(val);
}

/****************CLIENT*****************************/

import processing.net.*; 
Client myClient; 
int dataIn; 

void setup() { 
  size(200, 200); 
  // Connect to the local machine at port 5204.
   myClient = new Client(this, "127.0.0.1", 5204);

} 

void draw() { 
  if (myClient.available() > 0) { 
    dataIn = myClient.read(); 
  } 
  background(dataIn); 
}

Answers

  • Depending on the way that your house's LAN is set up, you might have firewalls or other obstructions blocking external access to your local server. It might be necessary to port forward the machine that you're running the server on, but this can lead to security vulnerabilities.

  • edited May 2015

    Server side must have some kinda port forwarding. At the very least, a router's DMZ host pointing to the server's LAN IP! ^#(^

    Another option to activate a port forwarding is thru' UPnP, like programs such as µTorrent do!
    To get a UNnP port forwarding, you may try MiniUPnP. 8-X

  • Also if you use the 127.0.0.1 ip address in your client example you will not connect to anywhere :) as 127.0.0.1 is a "loopback" address, meaning that it is just "fake" address which points your computer to yourself. And it is not seen from the outside.

    After that what @calsign has mentioned applies: whether your home network server is seen from behind your router.

    And after that there's windows firewall, which may sometimes block your connection even within your home network (eg. when you have at home 2 computers connected to the same network, one running server, another client).

    I would suggest trying to debug your problem by trying to run your server and client apps INSIDE your home network. Try to have 2 laptops talking to each other first. This way you will be able to "debug" whether you have problems with firewall first.

    When your can see that two laptops within your home network talk to each other well, then you need to figure out whether you need port forwarding or not.

    First thing to check is to see: whether your home laptop IP is "global" or "local". This can be easily done: go to some webpage which tells you your IP address. Write down this address. Then in Windows open command line window and type ipconfig /all this will show you your ip address as one of the lines. Alternatively you can just right click on your internet connection icon and check properties/details.

    If the address you found on windows is same as ip-address reported to you by websites: then you need to make sure your router doesn't block incoming port connections (that's probably involves setting firewall settings on the router). But in this case you don't need port forwarding. Just check that firewall allows incoming port connections.

    If IP address on windows is different vs address reported by websites, then you need port-forwarding. Then you again need to log on to your router and set up a port, on router which will be forwarded to the port on your home laptop. After you have set up port forwarding at your work laptop, you will have to specify router IP address and port, and then this port will be forwarded to your home laptop port.

    as you can see, it's all pretty easy! ;)

  • edited November 2014

    I also experience the same problem. I tested to switch off firewalls on both systems, but again nothing happened. I provide into the client side the ip of the server machine.

    I would like to ask whether the server must know the CLIENT_IP or not?

    I am not providing any CLIENT_IP into the server code.

    Below you could see the two codes. Locally it runs, but not on 2 different machines.

    Thanks

    /****************SERVER*****************************/

    import processing.net.*;
    Server server;
    int val = 0;
    int[] mouse;
    boolean update;
    
    void setup() {
      size(320, 240);
      // Starts a myServer on port 5204
      server = new Server(this, 5204); 
    }
    
    void draw() {
    
      background(255);
      Client client=server.available();
      if(client!=null){
      String mousePos=client.readString();
      mouse=int(split(mousePos,","));
      noStroke();
      fill(0);
      update = true;
    }
      if (update && mouse.length == 2){
      ellipse(mouse[0],mouse[1],10,10);
      update=false;
    }
    }
    

    /****************CLIENT*****************************/

    import processing.net.*; 
    Client client; 
    
    
    void setup() { 
      size(320, 240);
      client = new Client(this, "192.168.0.210", 5204); 
      // Say hello
    
    } 
    
    void draw() {
      background(0);
    
      fill(255,100);
      ellipse(mouseX,mouseY,10,10);
      client.write(mouseX + "," + mouseY);
    }
    
  • Locally it runs, but not on 2 different machines.

    Do you mean that both Server & Client sketches are running from the very same machine? :-/
    In this case you should use the loopback 127.0.0.1 or localhost. *-:)

Sign In or Register to comment.