Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous message
Xemuth is currently offline  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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stopping ReadStdIn() function
Next Topic: How to configure for SDL2 project?
Goto Forum:
  


Current Time: Wed May 15 13:54:09 CEST 2024

Total time taken to generate the page: 0.01950 seconds