We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
i've tried the Server example:
//#################################################
import processing.net.*;
Server myServer;
int port =39999;
int val = 0;
String http_ok = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
void setup() {
size(200, 200);
// Starts a myServer 127.0.0.1 on port
myServer = new Server(this, port);
}
void draw() {
val = (val + 1) % 127;
background(val);
// Get the next available client
Client thisClient = myServer.available();
// If the client is not null, and says something, display what it said
if (thisClient != null) {
String whatClientSaid = thisClient.readString();
if (whatClientSaid != null) {
background(color(255,87,65));
println(thisClient.ip() + " at " + millis() + " =>\n" + whatClientSaid);
thisClient.write(http_ok);
thisClient.write("<!DOCTYPE HTML>\r\n");
thisClient.write("\r\n");
thisClient.write("Hello " + thisClient.ip() + "\t" + millis() + "\r\n");
thisClient.write("\r\n\r\n");
}
}
}
// The serverEvent function is called whenever a new client connects.
void serverEvent(Server server, Client client) {
String incomingMessage = "A new client has connected: " + client.ip();
println(incomingMessage);
}
//#################################################
This works perfectly from both local machine and local network when using putty.
But firefox hangs endlessly with "Transfering data...." ...
The server_event and draw() prints the connect log lines but then nothing more happens...
I use XP SP3, processing 2.0.3, firefox 24.0.
Appreciate any tips...
David
Answers
Is it possible that you have to close the connection after .write() so Firefox does not wait for more data?
Thanks hamoid,
I suppose the connection is closed automatically, the doc says so.
But I expected it to finish the transfer before that, as I said it does work with putty.
Anyway I also tried a delay(1000) after the last write but no success...
Just tested and reproduced the problem. Chrome displays the answer, but is hung too. Will investigate a bit more.
It just works if you add
after the thisClient.write() lines. See http://processing.org/reference/libraries/net/Server_disconnect_.html
Yes, it works!!!
Thank you very much!
But I get a "Client SocketException: Socket closed" in the server log window.
Maybe it does not matter...
Perhaps you try to write on the client after the server is disconnected from it.