text
stringlengths
0
2.2M
ofLogNotice() << "";
ofLogNotice() << "---------------------------------------";
ofLogNotice() << "testBlocking";
int port = ofRandom(15000, 65535);
ofxTCPServer server;
ofxTest(server.setup(port,true), "blocking server");
ofxTCPClient client;
ofxTest(client.setup("127.0.0.1",port,true), "blocking client");
// wait for connection to be made
server.waitConnectedClient(500);
std::string messageSent = "message";
ofxTest(client.send(messageSent), "send blocking from client");
ofxTestEq(server.receive(0), messageSent, "receive blocking from server");
ofxTest(server.send(0, messageSent), "send blocking from server");
ofxTestEq(client.receive(), messageSent, "receive blocking from client");
}
void disconnectionAutoDetection(){
ofLogNotice() << "";
ofLogNotice() << "---------------------------------------";
ofLogNotice() << "disconnectionAutoDetection";
int port = ofRandom(15000, 65535);
ofxTCPServer server;
ofxTest(server.setup(port,true), "blocking server");
ofxTCPClient client;
ofxTest(client.setup("127.0.0.1",port,true), "blocking client");
// wait for connection to be made
server.waitConnectedClient(500);
ofxTest(server.isConnected(), "server is still connected");
ofxTest(client.isConnected(), "client is still connected");
ofxTest(server.disconnectAllClients(), "server closes correctly");
ofxTest(!client.isConnected(), "client detects disconnection");
ofxTest(client.setup("127.0.0.1",port,true), "client reconnects");
ofxTest(client.close(), "client disconnects");
ofxTest(!server.isClientConnected(0), "server detects disconnection");
ofxTest(!server.isClientConnected(1), "server detects disconnection");
}
void testSendRaw(){
ofLogNotice() << "";
ofLogNotice() << "---------------------------------------";
ofLogNotice() << "testSendRaw";
int port = ofRandom(15000, 65535);
ofxTCPServer server;
ofxTest(server.setup(port,true), "blocking server");
ofxTCPClient client;
ofxTest(client.setup("127.0.0.1", port, true), "blocking client");
std::string messageSent = "message";
ofxTest(client.sendRaw(messageSent), "send blocking from client");
// wait for connection to be made
server.waitConnectedClient(500);
std::vector<char> messageReceived(messageSent.size()+1, 0);
std::size_t received = 0;
do{
auto ret = server.receiveRawBytes(0, messageReceived.data() + received, messageSent.size());
ofxTest(ret>0, "received blocking from server");
if(ret>0){
received += ret;
}else{
break;
}
}while(received<messageSent.size());
ofxTestEq(messageSent, std::string(messageReceived.data()), "messageSent == messageReceived");
}
void testSendRawBytes(){
ofLogNotice() << "";
ofLogNotice() << "---------------------------------------";
ofLogNotice() << "testSendRawBytes";
int port = ofRandom(15000, 65535);
ofxTCPServer server;
ofxTest(server.setup(port,true), "blocking server");
ofxTCPClient client;
ofxTest(client.setup("127.0.0.1", port, true), "blocking client");
// wait for connection to be made