program Project1;
{$APPTYPE CONSOLE}
uses
Windows,Sockets;
type
TConnection =
class
procedure Read(Sender: TObject; Socket: TCustomWinSocket);
procedure Disconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure Error(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure Connect(Sender: TObject; Socket: TCustomWinSocket);
end;
var
Connection: TConnection;
ClientSocket: TClientSocket;
Msg: TMsg;
ThreadID: DWORD;
ThreadHandle: THandle;
procedure TConnection.
Read(Sender: TObject; Socket: TCustomWinSocket);
begin
WriteLn(Socket.ReceiveText);
end;
procedure TConnection.Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
end;
procedure TConnection.Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
end;
procedure TConnection.Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
end;
procedure ConThread(zahl: Pointer)
stdcall;
begin
While Not ClientSocket.Socket.Connected
Do
begin
Sleep(500);
Clientsocket.Open;
end;
end;
begin
Connection := TConnection.Create;
ClientSocket := TClientSocket.Create;
ClientSocket.OnRead := Connection.
Read;
ClientSocket.OnError := Connection.Error;
ClientSocket.OnConnect := Connection.Connect;
ClientSocket.OnDisconnect := Connection.Disconnect;
ClientSocket.Host := '
localhost';
ClientSocket.Port := 123;
ThreadHandle:=CreateThread(
nil, 0, TFNThreadStartRoutine(@ConThread),
nil, 0, ThreadID);
If ThreadHandle <> 0
Then CloseHandle(ThreadHandle);
While True
Do
Begin
Sleep(100);
If PeekMessage(Msg, 0, 0, 0, PM_REMOVE)
Then
Begin
if Msg.
Message <> $0012
then
Begin
TranslateMessage(Msg);
DispatchMessage(Msg);
End
Else
Begin
Break;
End;
End;
end;
end.