struct sockaddr_in ClntAddr; /* Client address */
int cliLen = 16;
p=(PKT *)str;
for (int i=0; i<2; i++) {
recvfrom(sock, str, sizeof(PKT), 0,(struct sockaddr*) &ClntAddr, &cliLen);
if (p->Name == CLI01) // from client 1
data1=p->val;
if (p->Name == CLI02) // from client 2
data2=p->val;
}
p->val=(data1+data2)/2;
sendto(sock, str, sizeof(PKT), 0,(struct sockaddr*) &ClntAddr, 16); // ? how to send this to client1 ?
p->val=(data1+data2)/4; // assume;
sendto(sock, str, sizeof(PKT), 0,(struct sockaddr*) &ClntAddr, 16); // and send this to client2 ?
[edited by - safe on February 24, 2004 10:57:30 PM]
Problem about communication between 1 server, 2 clients
The server receive data1 and data2 from two clients, calculate result using data1 and data1. then send results back to the two clients.
Who can help me to solve this problem?
Thanks a lot!
This is the server side code:
man recvfrom
----------------------
ssize_t recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
If from is not NULL, and the socket is not connection-oriented, the source address of the message is filled in. The argument fromlen is a value-result parameter, initialized to the size of the buffer associated with from, and modified on return
to indicate the actual size of the address stored there.
----------------------
----------------------
ssize_t recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
If from is not NULL, and the socket is not connection-oriented, the source address of the message is filled in. The argument fromlen is a value-result parameter, initialized to the size of the buffer associated with from, and modified on return
to indicate the actual size of the address stored there.
----------------------
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement