views:

44

answers:

2

I need to connect to a remote server whose remote name and PORT number is specified to me. This I need to do over Unix sockets. After connecting with it, I will need to receive the messages the server sends and then send it data as it instructs me to do. I know the steps to make this client program but i'm lost as to the exact things I need to do. Also I am confused about getaddrinfo() and gethostbyname(). Can someone tell me how a real life client would do this. This may be a simple task but i am stuck as to how to start the coding. The implementation is to be done in C using gcc in linux.

Note: its not the IP Address but the remote server name given.

A: 

To get started with socket programming, you really can't go past Beej's Guide to Network Programming.

caf
Yuck! Not only is it cluttered with incorrect information, but it's a completely stupid read, instead look at UNIX Network Programming.
Mustapha Isyaku-Rabiu
A: 

You sure don't need either of those APIs if you are given a numeric IP and port.

You need to use them to fill in a sockaddr_in, and then you can call connect(2).

In short:

  1. socket, asking for PF_INET
  2. connect, passing in your address packaged as sockaddr_in
  3. read/write
  4. close
bmargulies