Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-12

FPC Listening with Sockets unit

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sir_Ty

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?

Michael Van Canneyt
to Sir_Ty
Sir_Ty wrote 49 lines
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.