 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
MuZZy Guest
|
Posted: Wed Mar 03, 2004 5:52 pm Post subject: Using ReadStrins for TcpServer connection |
|
|
Hi guys,
I just got a problem i really need help with:
I have a chat server listening to incoming messages, and here's wht i have:
procedure TChatForm.TcpServerExecute(AThread: TIdPeerThread);
Var
ChatMsgIp : String;
str_msg : TStringList;
Begin
ChatMessage := '';
With AThread.Connection Do
Begin
str_msg := TStringList.Create;
(0) ShowMessage('I het here!');
(1) ReadStrings(TStrings(str_msg));
(2) ShowMessage('I dont get here!');
ChatMessage := str_msg.Text;
str_msg.Free;
ChatMsgIp := AThread.Connection.Socket.Binding.PeerIP;
ChatMsgRecip := AddrBook.NameByAddr(ChatMsgIp);
If ChatMsgRecip = '' Then ChatMsgRecip := ChatMsgIp;
(3) AThread.Synchronize(AddChatMessage);
End;
End;
What happens is i get to line (1) and then for some reason all the lines
until (3) are skipped!!!
I inserted test showmessage lines before and after line (1) and the first
one(0) pops up, the second (2) doesn't...
If i do [F8] it comes to line (1) and then jumps right to line (3)...
So could someone help me figure out what's happening?
PS I cleaned all *.dcu's and .exe and recompile - same thing
Thank you,
Andrey
|
|
| Back to top |
|
 |
MuZZy Guest
|
Posted: Wed Mar 03, 2004 6:03 pm Post subject: Re: Using ReadStrins for TcpServer connection |
|
|
"MuZZy" <leyandrew (AT) yahoo (DOT) com> wrote
| Quote: | Hi guys,
I just got a problem i really need help with:
I have a chat server listening to incoming messages, and here's wht i
have:
procedure TChatForm.TcpServerExecute(AThread: TIdPeerThread);
Var
ChatMsgIp : String;
str_msg : TStringList;
Begin
ChatMessage := '';
With AThread.Connection Do
Begin
str_msg := TStringList.Create;
(0) ShowMessage('I het here!');
(1) ReadStrings(TStrings(str_msg));
(2) ShowMessage('I dont get here!');
ChatMessage := str_msg.Text;
str_msg.Free;
ChatMsgIp := AThread.Connection.Socket.Binding.PeerIP;
ChatMsgRecip := AddrBook.NameByAddr(ChatMsgIp);
If ChatMsgRecip = '' Then ChatMsgRecip := ChatMsgIp;
(3) AThread.Synchronize(AddChatMessage);
End;
End;
What happens is i get to line (1) and then for some reason all the lines
until (3) are skipped!!!
I inserted test showmessage lines before and after line (1) and the first
one(0) pops up, the second (2) doesn't...
If i do [F8] it comes to line (1) and then jumps right to line (3)...
So could someone help me figure out what's happening?
|
I just checked - it even doesn't do syncronization, so line (3) doesn't run
as well...
Seems like an exception is fired from ReadStrings, but delphi keeps
silence...
|
|
| Back to top |
|
 |
MuZZy Guest
|
Posted: Wed Mar 03, 2004 6:07 pm Post subject: Re: Using ReadStrins for TcpServer connection |
|
|
"MuZZy" <leyandrew (AT) yahoo (DOT) com> wrote
| Quote: | "MuZZy" <leyandrew (AT) yahoo (DOT) com> wrote in message
news:40461b97 (AT) newsgroups (DOT) borland.com...
Hi guys,
I just got a problem i really need help with:
I have a chat server listening to incoming messages, and here's wht i
have:
procedure TChatForm.TcpServerExecute(AThread: TIdPeerThread);
Var
ChatMsgIp : String;
str_msg : TStringList;
Begin
ChatMessage := '';
With AThread.Connection Do
Begin
str_msg := TStringList.Create;
(0) ShowMessage('I het here!');
(1) ReadStrings(TStrings(str_msg));
(2) ShowMessage('I dont get here!');
ChatMessage := str_msg.Text;
str_msg.Free;
ChatMsgIp := AThread.Connection.Socket.Binding.PeerIP;
ChatMsgRecip := AddrBook.NameByAddr(ChatMsgIp);
If ChatMsgRecip = '' Then ChatMsgRecip := ChatMsgIp;
(3) AThread.Synchronize(AddChatMessage);
End;
End;
What happens is i get to line (1) and then for some reason all the lines
until (3) are skipped!!!
I inserted test showmessage lines before and after line (1) and the
first
one(0) pops up, the second (2) doesn't...
If i do [F8] it comes to line (1) and then jumps right to line (3)...
So could someone help me figure out what's happening?
I just checked - it even doesn't do syncronization, so line (3) doesn't
run
as well...
Seems like an exception is fired from ReadStrings, but delphi keeps
silence...
|
Ok, i figured out - ReadStrings fires "Connection closed gracefully"
exception, so when i use try...except....end
it works..
BUT WHY THERE IS NO SINGLE WORD ABOUT READSTRINGS FIRING EXCEPTIONS?????
Andrey
|
|
| Back to top |
|
 |
Martin James Guest
|
Posted: Wed Mar 03, 2004 7:36 pm Post subject: Re: Using ReadStrins for TcpServer connection |
|
|
| Quote: |
BUT WHY THERE IS NO SINGLE WORD ABOUT READSTRINGS FIRING EXCEPTIONS?????
|
Well, readStrings calls readLn which is supposed to return an empty string
if connections are closed. Looking at the code, readLn calls readFromStack
with 'RaiseEceptionIfDisconnected'set to 'true'. There does not seem to be
any exception handler in readLn that could turn an exception from
'readFromStack' into a return with an empty string, so I guess the
disconnect exception bubbles all the way up to your thread.
There seems that there might be a slight discrepancy between the
documentation and implementation.
Either way, Indy throws an exception for almost everything, so why should
'readStrings' be much different? To some extent, you have yourself to share
the blame for this one as you started out with no exception handler :)
Rgds,
Martin
|
|
| Back to top |
|
 |
|
|
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
|
|