program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, Winsock2, Windows;
var
Data: WSAData;
SocketError: Integer;
ListenSocket: TSocket;
ClientSocket: TSocket;
SocketAddress: SockAddr_in;
SocketAddressSize: Integer;
MessageBytes: Integer;
recvbuf:
Array[0..511]
of Char;
begin
try
{ TODO -oUser -cConsole Main : Code hier einfügen }
SocketError := WSAStartup(MAKEWORD(2,2), Data);
if SocketError = 0
then
begin
ListenSocket := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if NOT ListenSocket = INVALID_SOCKET
then
begin
SocketAddress.sin_family := AF_INET;
SocketAddress.sin_port := htons(9000);
SocketAddress.sin_addr.S_addr := inet_addr(PAnsiChar('
127.0.0.1'));
SocketAddressSize := SizeOf(SockAddr_in);
SocketError := bind(ListenSocket, SocketAddress, SocketAddressSize);
// Hier der Fehler, auch nach der Änderung
if SocketError = 0
then
begin
SocketError := listen(ListenSocket, SOMAXCONN);
if SocketError = 0
then
begin
ClientSocket := accept(ListenSocket,
Nil,
Nil);
if ClientSocket = TSocket
then
begin
repeat
MessageBytes := recv(ClientSocket, recvbuf, SizeOf(recvbuf), 0);
Writeln(MessageBytes);
until MessageBytes = 0 ;
end;
end;
end;
end;
end;
closesocket(ClientSocket);
closesocket(ListenSocket);
WSACleanup;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
end.