 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Johan Korten Guest
|
Posted: Tue Dec 30, 2003 3:07 pm Post subject: strange behaviour with the IdTCPServer |
|
|
I'm experiencing strange behaviour with the IdTCPServer component:
Some messages are not delivered. The OnExecute event does not fire on them!
I'm making an IRC server. First I use the IdIRCServer component but since I
wanted to minimize options considering this problem I switched to
IdTCPServer what did not change the overall behaviour.
I am getting the first messages:
msg: 'NICK JopieK'
msg: 'USER johan_korten "hotmail.com" "192.168.0.120" :Johan Korten'
Then whatever I do, I'm getting this behaviour:
procedure TMainform.IdTCPServerExecute(AThread: TIdPeerThread);
var Messages : TStringList;
k : integer;
cmd, data : string;
datalist : TStringList;
begin
datalist := TStringList.Create;
datalist.Text := AThread.Connection.CurrentReadBuffer;
for k := 0 to datalist.Count -1 do
begin
processmessages(datalist.Strings[k], AThread);
end;
datalist.free;
end;
first message i send from Mirc or other IRC client is ignored (no OnExecute
fired)
next command is received, if I set a breakpoint on datalist.Text :=
AThread.Connection.CurrentReadBuffer; it stops there. However if I try to
step I lose the process (pressing F8, it acts like F9 was pressed) so I
assume that for some reason that piece of code IS being executed since it
sends back the desired message to the client!.
now I send the command (e.g. /nick JopieK1) for the third time and
everything works as expected.
I can't figure out what this is caused by... Time to drop Indy and search
for an alternative (since a TServerSocket just does it's job and does not
loose commands!)
Greetings and tnx for help!
Johan Korten
|
|
| Back to top |
|
 |
Johan Korten Guest
|
Posted: Tue Dec 30, 2003 3:19 pm Post subject: Re: strange behaviour with the IdTCPServer |
|
|
Hey guys,
strange, after working on it for hours, I did not solve it, after posting
here I solved it within no-time...
the problem is that I was sending using SendCmd instead of WriteLn so let
this be a warning, better use WriteLn or look carefully to the params of
SendCmd elsewise one gets crap!
Greetings and a happy old year!
"Johan Korten" <j.a.korten (AT) student (DOT) utwente.nl> wrote
| Quote: | I'm experiencing strange behaviour with the IdTCPServer component:
Some messages are not delivered. The OnExecute event does not fire on
them!
I'm making an IRC server. First I use the IdIRCServer component but since
I
wanted to minimize options considering this problem I switched to
IdTCPServer what did not change the overall behaviour.
I am getting the first messages:
msg: 'NICK JopieK'
msg: 'USER johan_korten "hotmail.com" "192.168.0.120" :Johan Korten'
Then whatever I do, I'm getting this behaviour:
procedure TMainform.IdTCPServerExecute(AThread: TIdPeerThread);
var Messages : TStringList;
k : integer;
cmd, data : string;
datalist : TStringList;
begin
datalist := TStringList.Create;
datalist.Text := AThread.Connection.CurrentReadBuffer;
for k := 0 to datalist.Count -1 do
begin
processmessages(datalist.Strings[k], AThread);
end;
datalist.free;
end;
first message i send from Mirc or other IRC client is ignored (no
OnExecute
fired)
next command is received, if I set a breakpoint on datalist.Text :=
AThread.Connection.CurrentReadBuffer; it stops there. However if I try to
step I lose the process (pressing F8, it acts like F9 was pressed) so I
assume that for some reason that piece of code IS being executed since it
sends back the desired message to the client!.
now I send the command (e.g. /nick JopieK1) for the third time and
everything works as expected.
I can't figure out what this is caused by... Time to drop Indy and search
for an alternative (since a TServerSocket just does it's job and does not
loose commands!)
Greetings and tnx for help!
Johan Korten
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Dec 30, 2003 6:36 pm Post subject: Re: strange behaviour with the IdTCPServer |
|
|
"Johan Korten" <j.a.korten (AT) student (DOT) utwente.nl> wrote
| Quote: | the problem is that I was sending using SendCmd instead
of WriteLn
|
That is not the cause of the problem. SendCmd() simply calls WriteLn()
internally. The real cause is that you are not reading the data correctly
in the first place on the server end.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Dec 30, 2003 6:41 pm Post subject: Re: strange behaviour with the IdTCPServer |
|
|
"Johan Korten" <j.a.korten (AT) student (DOT) utwente.nl> wrote
| Quote: | datalist := TStringList.Create;
datalist.Text := AThread.Connection.CurrentReadBuffer;
|
Why are you using CurrentReadBuffer()? That is going to read everything
that is currently available on the socket, which may contain multiple
packets as well as partial packets. TCP is just a byte stream, it has no
concept of individual blocks of data. That is the higher-level concept that
is the application's responsibility to handle, not the socket's. Since you
are apparently trying to read the socket data in lines, you should be using
ReadLn() instead of CurrentReadBuffer(), for example:
procedure TMainform.IdTCPServerExecute(AThread: TIdPeerThread);
var
begin
processmessages(AThread.Connection.ReadLn, AThread);
end;
| Quote: | first message i send from Mirc or other IRC client is ignored (no
OnExecute fired)
|
Since you are working with the IRC protocol, you really should go back to
using TIdIRCServer, that is what it was designed for. However, if you must
use TIdTCPServer directly, then I would suggest you look at using the
server's CommandHandlers collection instead of the OnExecute event. The
CommandHandlers will do all of the reading and parsing for you.
Gambit
|
|
| 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
|
|