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 & HelpSyntax Questions › java.net.socketexception with the Server
Page Index Toggle Pages: 1
java.net.socketexception with the Server (Read 380 times)
java.net.socketexception with the Server
Apr 28th, 2006, 1:12pm
 
Hi, I've just started programming in Processing and  I'm trying to write a simple server for an online game. The server needs to get 4 integers from one player and send them to the other player. I get the following error:

java.net.SocketException: socket closed
at java.net.PlainSocketImpl.socketAccept(Native Method)

Here is the source code:

import processing.net.*;

boolean myServerRunning = true;
Server myServer;
int xFirst,yFirst,xLast,yLast;

void setup()
{
 myServer = new Server(this, 10001);
}

if((keyPressed)&&(key == 'S')) {
   myServer.stop();
   myServerRunning = false;  
}

void draw()
{
 if (myServerRunning == true)
 {
   Client firstClient = myServer.available();
   if (thisClient != null) {
     if (thisClient.available() > 0) {
       xFirst = thisClient.read();
       yFirst = thisClient.read();
       xLast  = thisClient.read();
       yLast  = thisClient.read();
       Client secondClient = myServer.available();
       secondClient.write(xFirst);
       secondClient.write(yFirst);
       secondClient.write(xLast);
       secondClient.write(yLast);
     }
   }
 }
}

I've closed my firewall and tried different port numbers. Can you help me with this problem?
Page Index Toggle Pages: 1