J
Jack
Hi all
I need some help. I have 10 machines here and I want to write a peer
to peer tcp connection between them. So I have a main server that all
the machine's login to and get each other's IP address. As implied by
'peer to peer' I need these machines to talk to each other directly.
So my question is since in order to create a tcp connection between
two machine one has to write the following, do I need to write this 10
times (assuming one machine is creating the connection to 10 other
machines (including the server), or is there way way that I can
declare one socketChannel and have it connect to multiple IP
addresses. So here is my code for one machine..
struct sockaddr_in socketChannel;
int sd;
socketChannel.sin_family = AF_INET;
socketChannel.sin_port = htons(PORT);
inet_pton(AF_INET, serverIP, &socketChannel.sin_addr);
sd = socket (AF_INET, SOCK_STREAM, 0);
connect (sd, (struct sockaddr*) &socketChannel, sizeof(struct
sockaddr);
I guess I am wondering if there is a more efficient way to do this
rather than running 10 instances of sockaddr_in
Thanks
I need some help. I have 10 machines here and I want to write a peer
to peer tcp connection between them. So I have a main server that all
the machine's login to and get each other's IP address. As implied by
'peer to peer' I need these machines to talk to each other directly.
So my question is since in order to create a tcp connection between
two machine one has to write the following, do I need to write this 10
times (assuming one machine is creating the connection to 10 other
machines (including the server), or is there way way that I can
declare one socketChannel and have it connect to multiple IP
addresses. So here is my code for one machine..
struct sockaddr_in socketChannel;
int sd;
socketChannel.sin_family = AF_INET;
socketChannel.sin_port = htons(PORT);
inet_pton(AF_INET, serverIP, &socketChannel.sin_addr);
sd = socket (AF_INET, SOCK_STREAM, 0);
connect (sd, (struct sockaddr*) &socketChannel, sizeof(struct
sockaddr);
I guess I am wondering if there is a more efficient way to do this
rather than running 10 instances of sockaddr_in
Thanks