?
Solved

Problem with ClientSocket - SendText concatenates sent strings

Posted on 2003-02-21
8
Medium Priority
?
233 Views
Last Modified: 2010-04-04

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.
0
Comment
Question by:Zaytsev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:sfock
ID: 7993432
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
0
 
LVL 1

Expert Comment

by:keashF
ID: 7993464
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
0
 

Expert Comment

by:pderuiter
ID: 7993656
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Zaytsev
ID: 7993764
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"?

0
 
LVL 3

Expert Comment

by:sfock
ID: 7993881
> 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?
0
 

Author Comment

by:Zaytsev
ID: 7997966
>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?
0
 
LVL 3

Accepted Solution

by:
sfock earned 200 total points
ID: 7998257
well at first create a class, that exists on both sides client and server like

TRemoteCommand = class(TXMLObject)
 FCommand : string;
 FNickname : string;
 FResultList : TXMLList; // create this in the constructor
published
 property command : string read FCommand write FCommand;
 property Nickname : string read FCommand write FCommand;
 property Resultist : TXMLList read FResultList;
end;

If you are willing to send the command do something like
var
  cmd : TRemoteCommand;
begin
  cmd := TRemoteCommand.create;
  cmd.command := 'getulist';
  cmd.nickname := 'Guest';
  Socket.SendText(cmd.xml);
end;

on the serverside you do something like

var
  cmd : TRemoteCommand;
begin
  cmd := TRemoteCommand.create;
  cmd.xml := Socket.ReceiveText;
  // do with the infos in cmd what ever you like ...
end;

If you want to create the command more flexible or like a batch you may choos a TXMLCollection and TXMLCollectionItem as Transport objects

hope that helps
0
 

Author Comment

by:Zaytsev
ID: 8002172
'Thanks a lot! I will try that :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question