Advertisement

How to communicate between computers?

Started by February 23, 2004 05:19 PM
13 comments, last by safe 20 years, 11 months ago
Thanks.
I am not very clear why I need to use a HUB?
What is the advantage of using it, other than switches?

quote:
Original post by Anonymous Poster
Go and get a HUB


Whoever recommended the hub was probably kidding; a hub is much worse than a switch, because it always broadcasts on all ports when one machine is sending. It''s really dumb.

It sounds like your problem is simply "how can I easily figure out the neighbor in direction X from me" assuming a grid "NEWS" logical topology (north/east/west/south). That''s a fairly simple problem:

int get_neighbor_node( int me, int width, int height, int direction ){  int row = me / width;  int col = me % width;  switch( direction ) {    case NORTH:      return (row == 0) ? -1 : me-width;    case EAST:      return (col == width-1) ? -1 : me+1;    case WEST:      return (col == 0) ? -1 : me-1;    case SOUTH:      return (row == height-1) ? -1 : me+width;  }  assert( !"should not get here" );  return -1;} 


Assuming you''re node "me", in a grid of "width" by "height" nodes, this returns the node id of a neighbor in each of the directions, or -1 if there is no neighbor in that direction.

You probably need to come up with some configuration that will let you map a node id to an IP address. Simplest is to just add 2 to the "me" and tack it onto your "C" subnet, which then works for grids up to 253 machines. You should use .1 for routing to the external world, and 0/255 are reserved.
enum Bool { True, False, FileNotFound };
Advertisement
Thanks hplus0603!
My problem now is that: how to communicate between these nodes.

Take 12 as an example.
I assume 12 is server, 11 and 8 are clients.

The server receive data1 and data2 from two the clients, it calculate result using data1 and data1,then send results back to the two clients.

This is the server side code segment:
    struct sockaddr_in ClntAddr;      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 == CLI11) // from client 11                  data1=p->val;           if (p->Name == CLI08) // from client 8                  data2=p->val;    }    p->val=(data1+data2)/2;    sendto(sock, str, sizeof(PKT), 0,(struct sockaddr*) &ClntAddr, 16); // ? how to send this back to client11 ?     p->val=(data1+data2)/4; // assume;    sendto(sock, str, sizeof(PKT), 0,(struct sockaddr*) &ClntAddr, 16); // and send this to client8 ?          ... 


[edited by - safe on February 26, 2004 8:47:49 AM]
Firstly... what the HELL are you trying to build? The rest aside...

Anyway, to comment on your last post (the one with the code), the logic looks OK, although I''m not a 100% sure if recv is a blocking call.

In order to prevent the data loss mentioned in a post before, you can set up a log-in. For example the client first does a "HEY SERVER, YOU THERE??" before he starts computing. The the server says "YEH... I''M HERE... YOU CAN START".
Perhaps you already knew that... but I couldn''t get that out of your posts.

Now, I have the idea this is for a peer to peer like system for distributed computing (that''s what it looks like on first sight, with the calculations and stuff) and you might want to look into other P2P concepts like a supernode-concept or tree-concept. Those are usually better manageable than a grid-like system.

I think we can better help you if we know what you are trying to make. The diagrams make little sense on their own.
STOP THE PLANET!! I WANT TO GET OFF!!
Thanks Structural!

This topic is closed to new replies.

Advertisement