We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Help with client / server Networking
Page Index Toggle Pages: 1
Help with client / server Networking (Read 632 times)
Help with client / server Networking
Nov 4th, 2008, 11:03pm
 
When I try and get this code running on my school servers, it doesn't work, although it works fine here on my local computer.  I have a server process running.  Can I use 127.0.0.1 or do I need the real I.P. address the server is running on? (i assume it's the same local machine because the server is another processing applet in another folder in my home directory.)  

Server Code after the Client code.  

Quote:
import processing.net.*;
Client myClient;
int dataIn;
byte[] byteBuffer = new byte[10];

void setup(){
  frameRate(24);
  size(400,200);
  //    myClient = new Client(this, "127.0.0.1", 10020);

  background(255);
  PFont myFont = loadFont("ArialRoundedMTBold-14.vlw");
  textFont(myFont);
  fill(0);
}

void draw(){
  try{  
    text(myClient.ip(), 20, 130);
    if(myClient.available() > 0){
      String r = myClient.readString();
      text("Intercepted a Call from ",20,30);
      text(r, 20, 70);
    }
  }
  catch(Exception ex){
    fill(128);
    text("No Server", 30, 100);
  }
}

void mousePressed(){
  myClient = new Client(this, "127.0.0.1",10020);
}





Re: Help with client / server Networking
Reply #1 - Nov 4th, 2008, 11:03pm
 
I Guess I should post the server code too.  

Quote:
import processing.net.*;
import SpringGUI.*;

Server myServer;
SpringGUI gui;

void setup(){
 frameRate(30);
 size(480,320);
 background(255);
 myServer = new Server(this, 10020);

 PFont font = loadFont("TrebuchetMS-11.vlw");
 textFont(font);
 background(0,0,0);

 gui = new SpringGUI(this);
 
 gui.addTextField("myTextField","Enter Name and Number Here",10,40,180,20);
 gui.setBackground("myTextField",0,0,0);
 gui.setForeground("myTextField",255,255,255);

 gui.addTextField("time","Enter Time Here",10,80,180,20);
 gui.setBackground("time",0,0,0);
 gui.setForeground("time",255,255,255);

 gui.addList("myList",200,10,260,200);
 gui.setAllBackgrounds(54,54,54);
 gui.setAllForegrounds(255,255,255);
 
 gui.addButton("myButton","Send",200,230,260,20);
 gui.setBackground("myButton",0,0,0);
 gui.setForeground("myButton",255,255,255);


}

void draw(){

 //  background(0,0,0,10);
 fill(0,0,0,7);
 rect(0,0,width,height);

}


void handleEvent(String[] parameters){
 if(parameters[0].equals("TextField")&&parameters[2].equals("returnPressed")){
   String CallerID = gui.getText("myTextField");
   if(!CallerID.equals("")){
   CallerID += " " + gui.getText("time");
   myServer.write(CallerID);
   gui.setText("myTextField","");
   background(255,255,255);
   gui.addItem("myList", CallerID);
   }
 }
 
 if(parameters[1].equals("myButton")&&parameters[2].equals("mousePressed")){
   String reSend = gui.getSelectedItem("myList");
   myServer.write(reSend);
   background(255,255,255);
 }

 if(parameters[0].equals("Button")&&parameters[2].equals("mouseEntered")){
   gui.setBackground(parameters[1],164,0,0);
 }
 else if(parameters[0].equals("Button")&& parameters[2].equals("mouseExited")){
   gui.setBackground(parameters[1],64,64,64);
 }

 if ( parameters[0].equals("TextField") && parameters[2].equals("mouseEntered") ) {
   gui.setBackground(parameters[1], 0,128,164);
 }
 else if ( parameters[0].equals("TextField") && parameters[2].equals("mouseExited") ) {
   gui.setBackground(parameters[1], 64,64,64);
 }

}


Re: Help with client / server Networking
Reply #2 - Nov 5th, 2008, 11:28am
 
maybe the server is blocked by a firewall on your school computer?
Re: Help with client / server Networking
Reply #3 - Nov 21st, 2008, 4:44pm
 
Hey, still trying to figure this out.  Maybe I don't have the right mental model of what is going on.  When I create the server with

 myServer = new Server(this, 10020);

does "this" refer to the computer serving the webpage, or the computer the browser is running on?  

Similarly for
myClient = new Client(this, "127.0.0.1",10020);
Should the client be listening to the port on the computer that the webserver is on, or the local host?
Re: Help with client / server Networking
Reply #4 - Nov 21st, 2008, 5:33pm
 
deathbob wrote on Nov 21st, 2008, 4:44pm:
 myServer = new Server(this, 10020);

does "this" refer to the computer serving the webpage, or the computer the browser is running on

Neither, it refers to the running sketch (applet).

Quote:
Similarly for
myClient = new Client(this, "127.0.0.1",10020);
Should the client be listening to the port on the computer that the webserver is on, or the local host

It should be the same port anyway.

Did you tried to use the network IP address
I know that sometime you can have issues with localhost loopback, although I don't master these issues.

As dihardja points out, perhaps you should check if the school's computer has a firewall on, which might block this port (again, not sure if it works on localhost!).
Re: Help with client / server Networking
Reply #5 - Nov 21st, 2008, 5:44pm
 
Well that's what I'm trying to figure out.  Where is the applet running?  It seems like it's running in the browser, which makes me think the school firewall doesn't matter.  If both applets are running on the users computer, in the users browser, why would it matter if the school server had a firewall?  

If the applets are both running in the browser, they should work just like they do when i run them locally right?  Unfortunately that is not what is happening.  These programs run fine when i run them on my local computer, but do not work when I upload them to the school server and access them from there.  

Re: Help with client / server Networking
Reply #6 - Nov 21st, 2008, 11:42pm
 
I don't think the Java sandbox will let you run a server program in a browser and let anything connect to it. You'd have to run the server standalone from processing itself.
Page Index Toggle Pages: 1