If you’re using GNAT, the answer is to use GNAT.Sockets
; from the spec of that package, there’s the server side (with use GNAT.Sockets
):
Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1);
Address.Port := 5876;
Create_Socket (Server);
Set_Socket_Option
(Server,
Socket_Level,
(Reuse_Address, True));
Bind_Socket (Server, Address);
Listen_Socket (Server);
Accept_Socket (Server, Socket, Address);
and the client side:
Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1);
Address.Port := 5876;
Create_Socket (Socket);
Set_Socket_Option
(Socket,
Socket_Level,
(Reuse_Address, True));
Connect_Socket (Socket, Address);
If you’re not using GNAT, you may be lucky enough to find that your compiler provides an equivalent. If you’re using GNAT but want to see how they’ve done it, look at the body of GNAT.Sockets
.