Forum > Networking and Web Programming
Synapse: Reading data timeout
(1/1)
bpranoto:
Using synapse version 40.1 this code snippet fails to receive the string
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var FConn:TTCPBlockSocket .... if FConn.CanRead(3000) then begin FileVersion:=FConn.RecvString(12000); end;
However, if I change the code to:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- FileVersion:=''; Start:=GetTickCount64; while FileVersion='' do begin if FConn.CanRead(0) then begin FileVersion:=FConn.RecvString(12000); end; if (GetTickCount64 - Start)>1000 then begin // timeout break; end; end; if FileVersion <>'' then begin ... end; ....... It successfully receives the string
I think in the first verson, FConn.CanRead(3000) will wait for 3000 miliseconds to check if the string arrive, while in the secod version it only wait for 1000 ms to check. My question is why the first version fails even though it waits longer?
bpranoto:
It turns it is my fault.
On the server side, I use Indy and when I send message to the client, I add CRLF to the the message string like this:
Server
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// IndySelf.FContext.Connection.IOHandler.WriteLn(FileVersion+#13#10);
The synapse client, reading the file version string message
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- if FConn.CanRead(3000) then begin FileVersion:=FConn.RecvString(12000); end; it only fetch string, and the CRLF is still left in the buffer. when it retrieve the next message, it gets a CRLF which is an empty string.
Navigation
[0] Message Index