[fpc-pascal]FPC Listening with Sockets unit
Michael Van Canneyt
michael.vancanneyt at wisa.be
Mon Dec 18 09:31:51 CET 2000
On Sun, 17 Dec 2000, Sir_Ty wrote:
> On a Windows 95 box, FPC 1.02, etc. I'd like to set up a small server
> from my box to accept TCP/IP traffic to a specific port, number 3001.
> How do I set the port number to listen to in the address part of the
> bind command?
>
> It's written in the specs like this:
>
> 18.2.5 Bind
> Declaration
> Function Bind (Sock:Longint;Var Addr;AddrLen:Longint) : Boolean;
> Description
> Bind binds the socket Sock to address Addr. Addr has length Addrlen.
> The
> function returns True
> if the call was succesful, False if not.
>
> My best guess would be:
>
> .
> Const MyPort = 3001;
> .
> .
> .
> Bind(MySocket,MyPort,sizeOf(MyPort));
> .
> .
> .
>
> Of course, Addr could be type of TInetSockAddr like in other examples.
> Then I could set it like this:
>
> Var MyAddr : TInetSockAddr;
> .
> .
> .
> Addr.family:=AF_INET;
> { port 3001 in network order }
> Addr.port:=((11 shl 8) or 185);
> { localhost : 127.0.0.1 in network order }
> Addr.addr:=((1 shl 24) or 127);
> .
> .
> .
> Bind(MySocket,MyAddr,sizeOf(MyAddr));
> .
> .
> .
>
> Any ideas?
You should use the latter.
Michael.
More information about the fpc-pascal
mailing list