BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

tcpserver/client problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Dwight Crevelt
Guest





PostPosted: Fri Mar 18, 2005 4:29 am    Post subject: tcpserver/client problem Reply with quote



I am using a very simple client server setup with D7 and indy 9
For security/transaction reasons I can only allow one client request to be
processed by the server at a time.
I have tcpserver set to allow 1 connection.
When multiple tcpclient requests are attempted at the same time - one gets
in and the others
receive exception errors 10054 or 10053.

I am using repeat ..until blocks with the try..except imbedded to catch and
retry the requests.
However, sometimes the failure gets though and causes problems trying to
parse non-existent data.

Is there a better way to detect and retry client requests.

--
Dwight


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 18, 2005 5:03 am    Post subject: Re: tcpserver/client problem Reply with quote




"Dwight Crevelt" <dwight (AT) creveltcomputer (DOT) com> wrote


Quote:
the others receive exception errors 10054 or 10053.

That is to be expected. The server is accepting and then disconnecting the
connections right away, but the clients doesn't know the server is doing
that, so the first attempt to read from or write to the connection fails.

Quote:
I am using repeat ..until blocks with the try..except imbedded to
catch and retry the requests. However, sometimes the failure gets
though and causes problems trying to parse non-existent data.

Then you are not handling the errors properly. Please show your actual
code.


Gambit



Back to top
Dwight Crevelt
Guest





PostPosted: Fri Mar 18, 2005 5:21 am    Post subject: Re: tcpserver/client problem Reply with quote



Here is the an example:

Procedure tfipcomm.chkbarcode;
Begin
netcnt := 0;
repeat
inc(netcnt);
with idtcpclient1 do
begin
netcmd := 'chkbar: ';
neterror := false;
mstrsp := '-';
try
connect;
writeln('1'+station+barin);
mstrsp := readln;
except
on E: exception do
Begin
netmsg := E.Message;
networkerr;
end;
end;
if idtcpclient1.Connected then disconnect;
end;
until (netcnt > 10) or (not neterror);
if neterror then exit;

if mstrsp[3] = '0' then barok := true else barok := false;{ok}
if mstrsp[3] = '1' then barused := true else barused := false;{used}
if mstrsp[3] = '2' then barinv := true else barinv := false;{invalid}
if mstrsp[3] = '3' then barexp := true else barexp := false;{expired}
end;


Procedure tfipcomm.networkerr;
var
i: integer;
Begin
{network error}
i := pos('Gracefully',netmsg);
if i > 0 then exit;
netcntx := inttostr(netcnt)+' ';;
if netcnt > 3 then showmessage(netcmd+netcntx+netmsg+mstrsp);
neterror := true;
end;


--

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Dwight Crevelt" <dwight (AT) creveltcomputer (DOT) com> wrote in message
news:423a58b8 (AT) newsgroups (DOT) borland.com...

the others receive exception errors 10054 or 10053.

That is to be expected. The server is accepting and then disconnecting
the
connections right away, but the clients doesn't know the server is doing
that, so the first attempt to read from or write to the connection fails.

I am using repeat ..until blocks with the try..except imbedded to
catch and retry the requests. However, sometimes the failure gets
though and causes problems trying to parse non-existent data.

Then you are not handling the errors properly. Please show your actual
code.


Gambit





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 18, 2005 9:09 am    Post subject: Re: tcpserver/client problem Reply with quote


"Dwight Crevelt" <dwight (AT) creveltcomputer (DOT) com> wrote


Quote:
Here is the an example:

As I suspected, you are not handling errors correctly. You are ignoring
"Connection Closed Gracefully" exceptions, which in your case really are
errors. The server gracefully disconnected the socket immediately so you
could not get any data from it. Thus, you should be treating that exception
like any other error.

Try this instead:

procedure tfipcomm.chkbarcode;
begin
netcmd := 'chkbar: ';
For netcnt := 1 to 10 do
begin
neterror := false;
mstrsp := '-';
with IdTCPClient1 do try
Connect;
try
WriteLn('1' + station + barin);
mstrsp := ReadLn;
finally
Disconnect;
end;
// TODO: make sure mstrsp really is at least 3 characters
// in length before trying to access its third character
barok := (mstrsp[3] = '0');
barused := (mstrsp[3] = '1');
barinv := (mstrsp[3] = '2');
barexp := (mstrsp[3] = '3');
Exit;
except
on E: Exception do
begin
netmsg := E.Message;
networkerr;
end;
end;
end;
end;

procedure tfipcomm.networkerr;
begin
{network error}
neterror := true;
netcntx := IntToStr(netcnt) + ' ';
if netcnt > 3 then ShowMessage(netcmd + netcntx + netmsg + mstrsp);
end;


Gambit



Back to top
Dwight Crevelt
Guest





PostPosted: Sun Mar 20, 2005 6:04 pm    Post subject: Re: tcpserver/client problem Reply with quote

That took care of it, Thanks

I just needed a fresh set of eyes on the problem

-- "Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Dwight Crevelt" <dwight (AT) creveltcomputer (DOT) com> wrote in message
news:423a64df$1 (AT) newsgroups (DOT) borland.com...

Here is the an example:

As I suspected, you are not handling errors correctly. You are ignoring
"Connection Closed Gracefully" exceptions, which in your case really are
errors. The server gracefully disconnected the socket immediately so you
could not get any data from it. Thus, you should be treating that
exception
like any other error.

Try this instead:

procedure tfipcomm.chkbarcode;
begin
netcmd := 'chkbar: ';
For netcnt := 1 to 10 do
begin
neterror := false;
mstrsp := '-';
with IdTCPClient1 do try
Connect;
try
WriteLn('1' + station + barin);
mstrsp := ReadLn;
finally
Disconnect;
end;
// TODO: make sure mstrsp really is at least 3 characters
// in length before trying to access its third character
barok := (mstrsp[3] = '0');
barused := (mstrsp[3] = '1');
barinv := (mstrsp[3] = '2');
barexp := (mstrsp[3] = '3');
Exit;
except
on E: Exception do
begin
netmsg := E.Message;
networkerr;
end;
end;
end;
end;

procedure tfipcomm.networkerr;
begin
{network error}
neterror := true;
netcntx := IntToStr(netcnt) + ' ';
if netcnt > 3 then ShowMessage(netcmd + netcntx + netmsg +
mstrsp);
end;


Gambit





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.