Link to home
Start Free TrialLog in
Avatar of Zaytsev
Zaytsev

asked on

Problem with ClientSocket - SendText concatenates sent strings


Hello,

My problem is following: I am writing a very simple chat server/client with

a userlist. The userlist is stored on server, and each client should send

it's nickname on connect and get the list of currently talking users. So I

have the following OnConnect code:

procedure TfrmClient.CliSocketConnect(Sender: TObject; Socket:

TCustomWinSocket);
begin
  Msg('[Connected]');
  Socket.SendText(sSysTag + ' ' + sCmdGetUList);
  Socket.SendText(sSysTag + ' ' + sCmdNick + ' ' + edNick.Text);
  btnConnect.Caption := 'Disconnect';
end;

However, the server receives both commands in the single string, like this:

"zsystem getulistzsystem nick Guest"

Eventually my command-recognizing function fails. Is there a way to send

this so server receives 2 different commands, like this:

"zsystem getulist"
"zsystem nick Guest"

Thanks in advance,
Yury.
Avatar of sfock
sfock

how about sending XML instead of flat commands?

I'd use XMLWorks. creating a simple Object to enpackage the info like

TmyObj = class(TXMLObject)
published
  property command : string ...
  property Nickname : string ...
end;

then creating it at the client sending it's xml property to the server
and serverside creating it to and assigning the received XML to it and here you are

you can get XMLWorks as an open Source project from the D7 companion CD or at http://www.xmlworks.de/de/index.php
this happens because te socket can not know when you want your string to end.
i had the same problem some time ago and i solved it by adding a termination symbol at the end of each line (something that is most unlikely to occur in a normal string, like '|'). then, of course, the receiver must separate the received strings.

good lick
keashF
why dont you just send the userlist back when you receive a logon? no need for that seperate command is there?
Just send 1 command at a time
Avatar of Zaytsev

ASKER

Let's start...

...sfock, I use Delphi 5 and then, I do not want to use XML. Just a simple plain commands.

...keashF, that is what I was thinking about, but I thought that that should be a way to instruct ClientSocket to SEND the message on SendText, but not queque it and wait until there are some other messages to send... And then it will take many time from me to write a message-splitting code :-) I believe there should be a way to avoid cacheing...

...pderuiter, that is not the only situation when I need to send multiple commands from the same function. What do you mean by saying "at a time"?

> I use Delphi 5
that is no problem XMLWorks runs with D5 as well as with 6 or 7

>and then, I do not want to use XML. Just a simple plain commands
okay if you just don't want to ... what can i do? But do you allow me to ask what's so horrible with XML?
Avatar of Zaytsev

ASKER

>that is no problem XMLWorks runs with D5 as well as with 6 or 7
That's better. I visited their website and saw that.

Okay, I will try to implement you solution. What's so horrible with XML? Just that I have never worked with it before and most probably I'll have a lot of troubles with it. Besides, that seem to the the only reliable solution.
However, what should I do if SendText would concatenate my two consequent XML objects?
ASKER CERTIFIED SOLUTION
Avatar of sfock
sfock

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zaytsev

ASKER

'Thanks a lot! I will try that :-)