Registriert seit: 13. Mär 2004
22 Beiträge
Delphi 6 Enterprise
|
Re: TClientSocket/Server - Befehl senden mit edit text Speec
5. Dez 2004, 14:11
CLIENT:
Delphi-Quellcode:
// SENDEN von Strings
procedure TfrmMain.SendString(Cmd, Param1, Param2: String );
var
FullCmd: String;
begin
FullCmd := Cmd + ' ¬' +Param1+ ' ¬' +Param2+ ' ¬';
if ClientSocket1.Socket.Connected then
begin
ClientSocket1.Socket.SendText( FullCmd );
end else
begin
ShowMessage(' you are not connected!');
end;
end;
// READ STRINGS
procedure TfrmMain.ClientSocket1SockRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Data, Cmd, Param1, Param2: String;
begin
Data := Socket.ReceiveText;
//-
Cmd := Copy(Data, 1, Pos(' ¬', Data) -1);
Delete(Data, 1, Pos(' ¬', Data));
//-
Param1 := Copy(Data, 1, Pos(' ¬', Data) -1);
Delete(Data, 1, Pos(' ¬', Data));
//-
Param2 := Copy( Data, 1, Pos(' ¬', Data) -1);
Delete(Data, 1, Pos(' ¬', Data));
//-
if Cmd = ' Test' then
begin
MessageBoxA( Handle, pChar(Param1), pChar(' Client'), MB_ICONINFORMATION);
end;
..
..
end;
// SENDEN von Befehlen
procedure TfrmMain.Button1Click(Sender: TObject);
begin
// Sende Text aus Edit1 im Befehl 'Test'
SendString(' Test', Edit1.Text, ' ');
end;
SERVER:
Delphi-Quellcode:
// STRING Senden
procedure TfrmMain.SendString( Socket: TCustomWinSocket; Cmd, Param1, Param2: String );
var
FullCmd: String;
begin
FullCmd := Cmd + '¬' +Param1+ '¬' +Param2+ '¬';
Socket.Sendtext( FullCmd );
end;
// EMPFANGEN
procedure TfrmMain.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Data, Param1, Param2: String;
Cmd: Integer;
begin
Data := Socket.ReceiveText;
//-
Cmd := Copy(Data, 1, Pos('¬', Data) -1);
Delete(Data, 1, Pos('¬', Data));
//-
Param1 := Copy(Data, 1, Pos('¬', Data) -1);
Delete(Data, 1, Pos('¬', Data));
//-
Param2 := Copy( Data, 1, Pos('¬', Data) -1);
Delete(Data, 1, Pos('¬', Data));
//-
if Cmd = 'Test' then
begin
ShowMessage('Gesendeter Text: ' + Param1);
SendString(Socket, 'Test', 'Text ist angekommen...', ''); // So Sendet der Server befehle [ od. Antworten ]
end;
..
..
end;
du müsstest den code oben einfugen [ natürlich ohne dem test etc.. ]
und dein code würde zb. so aussehen
Delphi-Quellcode:
// Client #######
// Button1.Click:
SendString( ' Speech', Edit1.Text, ' ' ); // Param2 ist unnötig
// Server #######
// On Read:
if Cmd = ' Speech' then
begin
oleVoice := CreateOLEObject(' SAPI.SpVoice');
oleVoice.Speak(' Hello World!', 0);
// usw...
end;
|