var
lwsaData: WSADATA;
lsocket: TSOCKET;
clientService: sockaddr_in;
bytesSent: Integer;
bytesRecv: Integer;
sendbuf:
Array[0..31]
of Char;
recvbuf:
Array[0..31]
of Char;
begin
if WSAStartup(MAKEWORD(2,2), lwsaData) <> NO_ERROR
then
Exit;
lsocket := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if lsocket = INVALID_SOCKET
then
Exit;
clientService.sin_family := AF_INET;
clientService.sin_addr.s_addr := inet_addr('
128.30.52.24');
//w3c's ip-adress
clientService.sin_port := htons(80);
// port 7 to send echo's
if connect(lsocket, TSockAddr(clientService), sizeof(clientService)) = SOCKET_ERROR
then
ShowMessage('
N');
sendbuf := '
GET / HTTP/1.1'+#13#10+'
Host: w3c.org';
bytesRecv := SOCKET_ERROR;
bytesSent := send(lsocket, sendbuf, strlen(sendbuf), 0);
ShowMessage(IntToStr(bytesSent) + '
bytes sent out there');
while bytesRecv = SOCKET_ERROR
do
begin
ShowMessage(IntToStr(bytesRecv));
bytesRecv := recv(lSocket, recvbuf, 32, 0);
ShowMessage(IntToStr(bytesRecv));
if (bytesRecv = 0)
or (bytesRecv = WSAECONNRESET)
then
ShowMessage('
closed');
Application.ProcessMessages;
end;
WSACleanup();
ShowMessage('
j');