socket programming

my system is a stand alone system... i want to try doing socket porgramming..ihave heard that this is usually done during testing...
how can i do that....?

What do you mean by that ?

You can do it ( if you want to ) , get Unix Network programming e-book it's cool .. :smiley:

Even if your system doesn't have a network card it should have a loopback interface. This is sort of a virtual network card who's address is always 127.0.0.1. It supports TCP and UDP. You can host server sockets on it and connect to them the same way you'd do that with a network card except it never leaves your own machine.

yes i tried using that.. i programmed the server first in a port and it all went fine... but i dont think that my client is able to connect to that socket with 127.0.0.1... do u know how to check the connectivity...?

My psychic powers have failed me today. What, exactly, are you trying to run, and what, exactly, is going wrong?

How to check the conectivity ? You mean , if socket client connection goes well or wrong ?


if( connect(listener,(struct sockaddr *) &myaddr, sizeof(myaddr)) < 0)
        {
                  perror("Error on connection , please reconnect later !");
                  exit(2);
        }

If (< 0 ) is error , in connection . Supose you pre-declared , something like this .. in the client cont ..

#define PORT 1957 /* aleator port */

struct sockaddr_in myaddr; /* your address structure */


 myaddr.sin_family = AF_INET;
 myaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
 myaddr.sin_port = htons(PORT);

Listener , is the socket descriptor for the client .. something like this :




listener = socket(AF_INET, SOCK_STREAM, 0);

I mean , is AF_INET , but you can use AF_LOCAL , your using it only on your local computer/server .. SOCK_STREAM is for TCP ..

Maybe that was your problem ?

yes i did all those error handling.. i trid the same program that is given in unix network programming.... i tried to echo wat ever the client writes to the server.... the server part works well ... i configured the server with port 9877(as told by unp) ... when i run the client part , the console just prints "error" and nothing else... i didnt have any output to the stdout as "error"... i just dont know from where it is coming....:frowning: