How to read a data ( string of characters ) from a XXXXX port.

Hi people, I have a hardware ( no arduino ) sending data to my IP, to a port, and I have to read it with processing. I made in the pass the same with arduino and it was ok, but now, I have another hardware. the hardware send like: IP PORT data

Answers

  • well, it was working now it doesnt

    But you dont tell what hardware it is

    You dont show code

    So we can only guess

    is the ip and port in the new hardware right? Do you have a led or so to make sure, the program on the new hardware runs at all?

  • Hi Chrisir , thks for reply.. I have a running project that I am reading data from Arduino + GPS . I am reading in the serial port with the example function of proceesing. This code is working fine for me,.... BUT. now, I have another hardware, a xexunGPS that it is sending data via SIMCARD to a IP, and one PORT.

    and now, I need to read this new data to check them vs Arduino+GPS.

    then, my problem is that I don´t know how to configure processing to read this new port, example "20462" my hardware send data like : IP 20462 "data_string_to_read_with_processing"

  • // Example by Tom Igoe
    
    import processing.net.*; 
    Client myClient;
    int dataIn; 
    
    void setup() {
      size(200, 200);
      // Connect to the local machine at port 5204.
      // This example will not run if you haven't
      // previously started a server on this port.
      myClient = new Client(this, "127.0.0.1", 5204);
    }
    
    void draw() {
      if (myClient.available() > 0) {
    dataIn = myClient.read();
      }
      background(dataIn);
    }
    
  • edited August 2015

    you want to read 2 sources and compare them?

    • write two separate sketches first to test if the readings of both sources work separately

    next:

    join them :

    duplicate the relevant lines like

    • Client myClient2;

    etc. etc.

  • edited August 2015

    hi again and thks to community

    I get write and read in a port in localhost. 127.0.0.1

    but I dont´get in other ip ( one of my server )

    java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.<init>(Unknown Source) at java.net.Socket.<init>(Unknown Source) at processing.net.Client.<init>(Unknown Source) at read_dport.setup(read_port.java:31) at processing.core.PApplet.handleDraw(PApplet.java:2361) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source)

  • edited August 2015

    hi friends... I continue with this problem. in local mode , this code works fine

    // Example by Tom Igoe
        import processing.net.*; 
        Client myClient;
        int dataIn; 
    
        void setup() {
          size(200, 200);
          myClient = new Client(this, "127.0.0.1", 5204);
        }
    
        void draw() {
          if (myClient.available() > 0) {
        dataIn = myClient.read();
          }
          background(dataIn);
        }
    

    but in a server on internet only changing the IP, does not work I don´t understand. In the server, I have the port opened, and the firewall too. only change this line, with the IP server:

    myClient = new Client(this, "xxx.xxx.xxx.xxx", 5204);

    I have exported the script, like javascript, and like java too. anyway works.. any ideas...

  • thks for reply. I have checked that links , but I have not solved my issue.

    my server is a external hardware sending data. in this case, a GPS it sends data via sim card to my VPS. It sends, -IP - PORT - DATA-

    and in the server , I have that code running. This code reads the data of the GPS into "dataIn" . but it does not working.

    The computer is a VPS in internet, with the port opened, and the firewall´s rules opened as well.

    // Example by Tom Igoe
        import processing.net.*; 
        Client myClient;
        int dataIn; 
    
        void setup() {
          size(200, 200);
          myClient = new Client(this, "IP of the VPS", 5204);
        }
    
        void draw() {
          if (myClient.available() > 0) {
        dataIn = myClient.read();
          }
          background(dataIn);
        }
    
  • edited August 2015

    The computer is a VPS in internet, with the port opened, and the firewall's rules opened as well.

    • I don't get what you mean by "with the port opened".
    • Is it a synonym for "firewall's rules opened"? Or does it mean something else? :-??
    • In order for a server to actually be a server, it needs "port forwarding"! >-)
    • If that server has access to its router, it can either manually setup a port to point to its LAN IP...
    • Or alternatively, activate DMZ to point to its LAN IP.
    • If neither of those are possible, but the UPnP service is turned on in its router, it can instead rely on a program such as MiniUPnP to setup the port forwarding as a last resort.
    • Setting up a server involves many tasks. That's why I've posted that link in my reply above. 8-|
  • hi GoToLoop. thks for reply. 1.- yes, my VPS has the firewall rules opened for that port like this : iptables -A INPUT -p tcp -m tcp --dport 50240 -j ACCEPT

    2.- for expample : I have this script working in my house computer, this working fine, I write in a port, and I read it with the same script... then I upload it to my VPS server on internet, and it does not work.

    import processing.net.*; 
    Server myServer; 
    Client myClient; 
    String inString;
    byte interesting = 10;  // 10 ascii
    int port = 50240; 
    int i=0;
    
    void setup() { 
      size (600,600);      
      background(0);    
      //Starts a myServer on port 
      myServer = new Server (this, port, "localhost");   
      // Connect to the local machine at port 
      myClient = new Client(this, "localhost", port);  
    
    } 
    void draw() { 
        i++;
        delay (100);
        background(0);  
        //write
        myServer.write(i); 
        //read
        if (myClient.available() > 0) 
          { 
          inString = myClient.readString(); 
          println(inString);   //check in console
          text(inString, 10, 25); //write in graphic mode
          }    
    }
    
  • edited August 2015
    • I don't have much experience w/ servers either. So my help is very limited!
    • You don't seem to have researched any of my tips either.
    • You're still mixing up "open a firewall port" w/ "port-forwarding"! :-<
  • edited August 2015

    :) I am reading all your links . all of them. thks for advices :) I am not a professional admin for servers either because of that I don´t sure if I need to make "port forwarding".
    In that script I am writing in a port, and I am reading from in. The script is running in a server .... If I need port-forwarding, I don´t understat what ? and why ? maybe, like you see, I am mixing things. I ´m not sure.

    • By "server" you mean a 3rd-party service or a computer you have access to?
    • Repeating once again, a computer isn't a server till it got port-forwarding working properly.
    • Of course a 3rd-party server service got its computers fully configured to be such!
  • edited August 2015

    thks for reply ...

    Server, is a VPS, that I have with the compnay myhosting.com . You can check that code it does not work. and if you uses it in home ,all is ok ...

  • Do you have your Processing code currently running there as a server?
    You just need to know some port which is configured to port-forwarding to the LAN IP running the server app.

  • yes. I have uploaded this code to the forum processing guys !! , for you :)

    the port that I am using is one port that I have opened via iptables. and in the firewall rules is ok. Do you think that I need anything more ? How ?

  • edited August 2015

    How many times do I have to repeat myself that w/o port-forwarding there ain't no server?
    Haven't I already told you that opening firewall ports got nothing to do w/ the former?
    Read my replies since the beginning paying attention...

    P.S.: That link simply redirects me to Java's download page!

  • hi GoToLoop. thks for you patince :) I am c++ programmer, and I have not idea about sys admin. I am going to read more about it. I am lost in my CentOS server :) thks for all.

Sign In or Register to comment.