Hi,
Ich benutze grad die TServerSocket und TClientSocket Klassen. Habe hier ne Konsolenanwendung und das Problem ist folgendes: Es geht nicht
Ne im ernst.. Irgendwie kriege ich keine Verbindung zu stande
Was is denn das Problem ?
Delphi-Quellcode:
// Server
constructor TMyServerSocket.Create;
begin
inherited Create;
Server := TServerSocket.Create(nil);
Server.OnClientConnect := OnConnect;
Server.ServerType := stNonBlocking;
end;
function TMyServerSocket.Initialize: Boolean;
begin
Result := false;
FInit := false;
try
Server.Open;
FInit := true;
except
Result := FInit;
end;
end;
procedure TMyServerSocket.OnConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Writeln(Socket.LocalAddress + ' connected!');
end;
// Client
constructor TMyClientSocket.Create;
begin
inherited Create;
Client := TClientSocket.Create(nil);
end;
function TMyClientSocket.Connect: Boolean;
begin
Client.Open;
Result := Connected;
end;
Client Programm:
Delphi-Quellcode:
program Console_TCP_Client;
{$APPTYPE CONSOLE}
uses
SysUtils,
ClientClass;
var Client: TMyClientSocket;
begin
Client := TMyClientSocket.Create;
Client.Host := '127.0.0.1';
Client.Port := 1234;
readln;
Client.Connect;
if Client.Connected then
Writeln('Connected');
readln;
end.
Server Programm:
Delphi-Quellcode:
program Console_TCP;
{$APPTYPE CONSOLE}
uses
SysUtils, ServerClass;
var Server: TMyServerSocket;
begin
Server := TMyServerSocket.Create;
Server.Port := 1234;
Server.Initialize;
readln;
Server.Free;
end.
Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."