Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I need to transfer data between two pc's say PC1 and PC2 keeping a third pc say SERVER between them. So i want to write a client program that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! asadujjaman's Avatar
    Join Date
    Apr 2007
    Location
    ~
    Posts
    51

    Connecting two clients by help of a server


    Hi, I need to transfer data between two pc's say PC1 and PC2 keeping a third pc say SERVER between them. So i want to write a client program that will run on both PC1 and PC2 and a server program that will run on SERVER.

    I use c++. So, using the linux socket's api.

    Please tell me the best way to accomplish this.

  2. #2
    Linux Newbie dilbert's Avatar
    Join Date
    Sep 2006
    Location
    Yorkshire, GB
    Posts
    237
    The basic programs for setting up a TCP/IP (?) client and server are pretty short and simple. I got mine from a small book what's at home, now.

    If you really don't find anything appropriate ask again and I can post title and ISBN number.

    But it's mainly starting with the function open(), eventually bind() to bind the socket to a device.

    If you add to your Web search the name of the header files "sys/socket.h", "arpa/inet.h" and "net/if.h", you might get better results.

    Most code will be in C, but shouldn't be a great deal to feed it into g++.
    Bus Error: Passengers dumped. Hech gap yo'q.

  3. #3
    Just Joined! asadujjaman's Avatar
    Join Date
    Apr 2007
    Location
    ~
    Posts
    51
    I have written programs for commucation between two pc's. So, basic connection establishing is not a problem. The problem is how the server passes data from one client to the other. Obviously, the server may recv()
    data at one port from Client1 and send() it to another port for Client2. The main thing I need is to know when there is some data available from Client1 to be recv()ed. Continuous polling througout the server machine's runnig span
    may be very much inefficient specially when Client1 is going to say something at any unpredictible time for short period only. Is there any possibility for a notification?

    Quote Originally Posted by dilbert View Post
    The basic programs for setting up a TCP/IP (?) client and server are pretty short and simple. I got mine from a small book what's at home, now.

    If you really don't find anything appropriate ask again and I can post title and ISBN number.

    But it's mainly starting with the function open(), eventually bind() to bind the socket to a device.

    If you add to your Web search the name of the header files "sys/socket.h", "arpa/inet.h" and "net/if.h", you might get better results.

    Most code will be in C, but shouldn't be a great deal to feed it into g++.

  4. #4
    Linux Newbie dilbert's Avatar
    Join Date
    Sep 2006
    Location
    Yorkshire, GB
    Posts
    237
    I think notification could be done with the generic Unix tools like signals, message queues or shared ressources.

    If the server has nothing else to do, polling wouldn't be ineffective. The network stack runs eitherway with the least priority.

    But is what you are doing not simply Ethernet bridging? I think, a server receives a query from client 1 and sends a response, usually from an application running on that server, back to client 1. Then, it handles client 2 in the same way as client 1, but indepently from client 1.

    I wrote once a small app that acts as a bridge, i.e. it reads from socket 1 and writes the received packet to socket 2, and reads from socket 2 and writes to socket 1.

    This is in an endless while loop. One socket reads with "recv (sock_0, pkt, MTU, MSG_DONTWAIT)" and then does a "send (sock_1, (unsigned char *) pkt, pktLen, 0)". Then the other socket does the same.

    I remember that for some reason I selected MSG_DONTWAIT, but forgot exactly the reason why. "man recv" could shed some light on this.
    Bus Error: Passengers dumped. Hech gap yo'q.

  5. #5
    Just Joined! asadujjaman's Avatar
    Join Date
    Apr 2007
    Location
    ~
    Posts
    51
    Well i have found the solution. It nearly matches yours. But i am using the waiting mode.

    Quote Originally Posted by dilbert View Post
    ...

    This is in an endless while loop. One socket reads with "recv (sock_0, pkt, MTU, MSG_DONTWAIT)" and then does a "send (sock_1, (unsigned char *) pkt, pktLen, 0)". Then the other socket does the same.

    I remember that for some reason I selected MSG_DONTWAIT, but forgot exactly the reason why. "man recv" could shed some light on this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •