Interview Questions

How to use "connect" function ?

Perl, Sockets and TCP/IP Networking


(Continued from previous question...)

How to use "connect" function ?

You need to connect to the server with the connect function. This can get a bit tricky in Perl if you don't have the most recent versions of the Socket module, primarily because it's hard to specify the server's address. The syntax of the connect function is:

connect SOCKET, NAME

SOCKET is the file handle created by the socket function, so that's easy. The NAME argument, however, is described as a ``packed network address of the proper type for the socket'', which might leave you scratching your head if you're not already familiar with sockets. For Internet applications, the proper type of network address for the C version of the connect function is given by structures something like those in Listing 1 (from either or ).

(Continued on next question...)

Other Interview Questions