Client:
var
SockAddrIn: TSockAddrIn;
s := socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
SockAddrIn.sin_family := PF_INET;
SockAddrIn.sin_addr.s_addr := inet_addr(PChar(Address));
SockAddrIn.sin_port := htons(Port);
connect(s, SockAddrIn, SizeOf(SockAddrIn));
send(s, buf, len, 0);
n := recv(s, buf, len, 0);
...
closesocket(s);
Server:
var
SockAddrIn: TSockAddrIn;
ss := socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
SockAddrIn.sin_family := PF_INET;
SockAddrIn.sin_addr.s_addr := INADDR_ANY;
SockAddrIn.sin_port := htons(Port);
bind(ss, SockAddrIn, SizeOf(SockAddrIn));
listen(ss, 5);
while not Terminated do
begin
s := accept(ss, nil, nil);
// create a thread to perform send/recv on s, remember to close it finally
end;
closesocket(ss);