Hello everyone,
I have a simple server code that accepts a connection and returns whatever the client send in back to it. The server works fine if each client correctly closes the connection (by calling closeSocket(socket) on the client side) when the client finishes. But if I close an active connection in the middle of the connection, the next connection made by a client won't be accepted by the server.
I have searched for solution the past few days but no luck.
Please help!
#include <Bridge.h>
#include <BridgeServer.h>
#include <BridgeClient.h>
const int PORT = 5000;
BridgeServer server(PORT);
void setup() {
//begin bridge
Bridge.begin();
//begin server
server.begin();
}
void loop() {
//waiting for connection
BridgeClient client = server.accept();
//if there is a connection
if (client) {
while (client.connected()) {
if (client.available() > 0) {
//receive a 1-byte data from client
byte data = client.read();
//send data back to client
client.write(data);
//wait a bit
delay(50);
}
}
}
}