Home » Community » Newbie corner » my TCP client/server don't work correctly
Re: my TCP client/server don't work correctly [message #57051 is a reply to message #57050] |
Tue, 18 May 2021 08:42 |
|
Xemuth
Messages: 387 Registered: August 2018 Location: France
|
Senior Member |
|
|
Indeed it make sense...
will give a try after work.
Thanks again Oblivion
Edit : It worked fine, here is the code I come up with (not perfect and Many thing need to be added but it might help) :
if(!server.Listen(port, 1)) {
LOG("Unable to initialize server socket on port " + AsString(port));
return;
}
client.GlobalTimeout(1000);
LOG("Waiting for webServer...");
while(!Thread::IsShutdownThreads()){
if(client.Accept(server)){
LOG("WebServer connected");
int emptyData = 0;
while(!client.IsError()){
Upp::String data = client.GetLine();
if(!client.IsTimeout()){
Upp::String sendingCmd = "";
LOG("Receiving : " + data + " from: " + client.GetPeerAddr());
sendingCmd = ProcessCommandNetwork(data);
LOG("Sending: " + sendingCmd + " To: " + client.GetPeerAddr());
sendingCmd += '\n';
sendingCmd.Shrink();
client.Put(sendingCmd);
}else{
client.ClearError();
}
}
LOG("WebServer error: " + client.GetErrorDesc());
client.Close();
client.Clear();
LOG("WebServer disconnected");
}
}
LOG("Connection with webServer ended");
[Updated on: Wed, 19 May 2021 08:49] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed May 15 13:54:09 CEST 2024
Total time taken to generate the page: 0.01950 seconds
|