I'm trying to build my simple xmpp client to avoid using 3rd party components cause I need only some very basic functions like new account registration and sending messages (e.g. a basic jabber bot).
I'm not completely new to Delphi and even to Synapse (was using it's HTTPsend class before), but I am relatively new at sending data through TCP/IP socket and am stuck with some problems.
Basically, I've read about XMPP protocol specs and found out it is relatively simple to deal with, because it uses XML and is well-explained. I started with capturing some packets from a real client communicated with XMPP server. The very first task I decided to implement was new account creation.
Here is what the client sent to the server:
These are the initial packets.
Now comes the problem.
I wrote the following function to maintain sending xml to the server and read the response
function sndq(const query: string;sock: ttcpblocksocket): string;
var c: string;
i: integer;
begin
result:='';
sock.SendString(query);
c:='';
for i := 0 to 5000 do begin
c:=Sock.RecvBufferStr(1, 2500);
result := result + c;
end;// for i
end;:
First of all, I feel very wrong about doing that for...doing thing, but I tried using sock.waitingdata and waitingdataex, but it somehow returns wrong value (less then actual response size).
But the bigger problem is that I can only receive the first packet. So Here is the code I've written:
var sock: ttcpblocksocket;
begin
sock:=ttcpblocksocket.Create;
sock.Connect('exploit.im','5222');
writeln(sndq('<stream:stream to="exploit.im" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" xml:lang="ru" version="1.0" />',sock)); // goes well as I get that same initial packet as the client
writeln('----------');
writeln(sndq('<iq type="get" id="qip_0"><query xmlns="jabber:iq:register" /></iq>',sock)); // шлем запрос точно как у Квипа // prints empty line
readln; end.
I hope that I've explained my problem well.
Probably these questions are already answered but I wasn't able to find any way around, so please point out what do I have to correct in the code above (about determining actual response size and about being able to receive only a packet). Thanks.