Thread: client server on same machine?

  1. #1
    mwagiru
    Guest

    client server on same machine?

    Is there a way of making the same machine be the server and client in socket programming?
    I need to send a message from one machine the other but on the same machine?

  2. #2
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    yes there is.
    assume the server listens on port 9999 on your local ip. (192.168.0.1 for instance)

    the client now needs your ip and the port the server listens on.
    nothing more.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    Originally posted by threahdead
    yes there is.
    assume the server listens on port 9999 on your local ip. (192.168.0.1 for instance)

    the client now needs your ip and the port the server listens on.
    nothing more.
    That's true but it's better to use the loopback (127.0.0.1) rather than an IP address if you're doing it all on the localhost. If the IP changes then your program is borked....the loopback will never change.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

  4. #4
    mwagiru
    Guest

    sending files...

    Apart from the loop back address is there another way of making the server part run on the background while I run the client(in Linux/Unix)?


    I would like to modify the server part so that it can send a file of a particular format.Need help...


    #include <sys/types.h>
    #include <sys/socket.h>
    blah...
    blah...
    /*Socket creation and binding part omitted*/



    /*This part is to send or receive a message to/from a client*/
    printf("%s: waiting for data on port UDP %u\n",
    argv[0],LOCAL_SERVER_PORT)

    while(1) {


    memset(msg,0x0,MAX_MSG);
    cliLen = sizeof(cliAddr)
    n = recvfrom(sd, msg, MAX_MSG, 0,
    (struct sockaddr *) &cliAddr, &cliLen);
    printf("%s: cannot receive data \n",argv[0]);
    continue;
    }

    /* print received message */
    printf("%s: from %s:UDP%u : %s \n",
    argv[0],inet_ntoa(cliAddr.sin_addr),
    ntohs(cliAddr.sin_port),msg);

    }

    return 0;

    }




    Salem:Smart link!Helps a lot, thank you!

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    You can type ./server_program & to start the server program and return you to a prompt so you can run the client program.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. server client application - (i really need your help)
    By sarahnetworking in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 10:54 PM
  2. Socket Programming Problem!!!!
    By bobthebullet990 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-21-2008, 07:36 PM
  3. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  4. Unicode vurses Non Unicode client server application with winsock2 query?
    By dp_76 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-16-2005, 07:26 AM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM