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.
- 04-24-2007 #1
Connecting two clients by help of a server
I use c++. So, using the linux socket's api.
Please tell me the best way to accomplish this.
- 04-25-2007 #2
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.
- 04-29-2007 #3
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?
- 05-04-2007 #4
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.
- 05-06-2007 #5