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 » TcpSocket, Know when distant connection have been closed
TcpSocket, Know when distant connection have been closed [message #57216] Sat, 12 June 2021 17:10 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello U++ !
I'm programming an application which rely on TcpSocket and Json sending & receiving.
A web server ask for data via a JSON command and I send him a formatted JSON. Here is how I do it :
while(!d_stopThread && !d_activeConnection.IsError() && d_activeConnection.IsOpen()){
	if(d_activeConnection.WaitRead()){
		Upp::String data;
		while(d_activeConnection.Peek()!= -1){
			data << char(d_activeConnection.Get());
		}
		
		if(data.GetCount() > 0){
			Upp::String sendingCmd = "";
			LLOG("[Server][Listener] Receiving  from web server: " + data.Left(20));
			sendingCmd = d_callbackServer(d_socket, data);
			if(sendingCmd.GetCount() > 0){
				LLOG("[Server][Listener] Sending to web server: " + sendingCmd.Left(20));
				d_activeConnection.Put(sendingCmd + "\n\0");
			}
		}
	}else{
		if(d_activeConnection.GetSOCKET() == -1)
			break;
		else
			Sleep(100);
	}
}
if(d_activeConnection.IsError()) LLOG("[Server][Listener] WebServer error: " + d_socket.GetErrorDesc());
d_activeConnection.Clear();
LLOG("[Server][Listener] WebServer disconnected");


The web server send me data in JSON, I retrieve this data then I send back a json with the requested data. Here are a wireshark screenshot :
https://i.imgur.com/vYieDMS.png

So here is my question, how to know when the distant socket have been closed ? I have trying many things but
either it's me who cuts the connection (probably because of a timeout or erro during WaitRead())
either I don't detect the FIN from the server side and dont react so my connection never reset

[Updated on: Sat, 12 June 2021 19:17]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: RichEdit with word wrap?
Next Topic: Calendar
Goto Forum:
  


Current Time: Wed May 15 04:38:29 CEST 2024

Total time taken to generate the page: 0.01556 seconds