I do not have much familiarity with Delphi 2010 and am having trouble with using components ClientSocket and ServerSocket. The question is simple: I am trying to send a text from a client to a server using the following code:
cliente.Socket.SendText('call');
On the server side I writed the following code:
procedure TForm6.ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
s: string;
begin
s:=Socket.ReceiveText;
if s = 'call' then
begin
showmessage('Client is Calling');
end;
end;
However, the server dont displaying the message. Could help me once more?
In D2009+, SendText()
and ReceiveText()
do not work correctly with Unicode strings. It is better to use SendBuf()
and ReceiveBuf()
directly instead.
With that said, TClientSocket
and TServerSocket
have been deprecated for a LONG time. You should use a different component set, such as Indy (which also ships with Delphi), eg:
IdTCPClient1.IOHandler.WriteLn('call');
procedure TForm6.IdTCPServer1Execute(AContext: TIdContext);
var
s: string;
begin
s := AContext.Connection.IOHandler.ReadLn;
if s = 'call' then
begin
// TIdTCPServer is a multi-threaded component,
// but ShowMessage() is not thread-safe...
Windows.MessageBox(0, 'Client is Calling', '', MB_OK);
end;
end;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.