: :
: :
[EDITED] : I Solved the first problem
: : :!!!
: :
: : Im back!(i was on vacation).
: :
: : I have some more questions , please , if you can help do it!
: :
: : 1)I tried to setup a test server&client(in delphi) , and here's what
: : i've got so far:
: :
: : Note: im using delphi's sockets...
: : Packet class:
: :
: :
: : //=================
: : type tNETPACKET=record
: : commandID:integer;
: : commandSTR:string;
: : end;
: : //=================
: :
: : //Send memory (client)
: : procedure tform1.senddata(cmd:integer;cmdstr:string);
: : var PACKET:TNETPACKET;
: : begin
: : PACKET.commandID:=cmd;
: : PACKET.commandSTR:=cmdstr;
: : cl.socket.SendBuf(PACKET,sizeof(packet));
: : end;
: :
: : //receieve memory (server)
: : //NOTE: RCPACK = tNETPACKET CLASS
: : procedure TForm1.SOCKETClientRead(Sender: TObject;
: : Socket: TCustomWinSocket);
: : var i:integer;
: : begin
: : //clear
: : rcPACK.commandID:=-1;
: : rcPACK.commandSTR:='';
: : //get the length and fill the class
: : i:=socket.ReceiveLength;
: : socket.ReceiveBuf(rcPACK,i);
: : //showmessage(INTTOSTr(i));
: : //test command '444'. print the message..
: : if (rcpack.commandID=444) then
: : showmessage((rcpack.commandstr));
: : end;
: :
: :
: : The above code returns an empty string("commandstr") , but the weird
: : thing is , that the "commandID"(int) value is correct.
: :
: : Also , if i send more than one command the server crashes(returns
: : error : external exception 800[more 0's]1).
: :
: : 2)Another thing.
: : The (real) client is written in C++.
: : All i have to do is to send the class?
: : my class looks like this:
: :
: :
: :
: : class gameobject
: : {
: : protected:
: : DATA[8];//health,x,y,w,h etc..
: :
: : public:
: : gameobject();
: : ~gameobject();
: : //more functions..
: : };
: : : :
: Delphi strings are very complex entities. They are in essence a
: reference counted, copy-on-change, PChar typed variable. Sending
: them requires some special coding. If your commands are never longer
: than 255 characters, I would suggest to change them into
: shortstrings. Those are simply an array[0..255] of char, where the
: 0-th char holds the length.
: If the commands can be longer than 255 characters, you first need to
: send the length (as integer), and then send all the bytes. The
: receiving end should read the length and then make a buffer as large
: as necessary to retrieve the string-data.
: In code:
:
:
: socket.ReceiveBuf(l, SizeOf(integer));
: SetLength(CommandStr, l);
: socket.ReceiveBuf(CommandStr[1], l);
:
:
:
Thanks zibadian.
Even if i program in delphi for 1 year(or so)...still im learning new things...