• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting up a system of 20 nodes (workstations) using Threads and Sockets  RSS feed

 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone out there, I'm a new person to this forum as well as a new programmer to Java. I have questions on how to do sockets and network programming in java, hope anyone one of you can help me out (as detail as possible would be MUCH appreciated).
I want to setup a system of 20 nodes(workstations) by just using Java's socket programming. There are reliable TCP connections between EACH pair of nodes, and I am to send timestamped messages over those connections for comparison.
I only know how to setup the simple 1 Server to Multi-Client scenario, because it is shown in most Java books, however, for the situation described above I am pretty clueless.
Does anyone have any suggestion or help on coding/designing such a connection?
Thank TONS,
Wang
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you clueless about? If you understand client-server, you should know that sockets are two-way connections. Have the client block on reading data from its socket and the server write data to one of its collection of sockets when it has data to process. Nothing unusual.
 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply, firstable!! Well, my problem is, I dont know how to setup a Multi-Server to Multi-Client situation. In the situation of 20 nodes I describd above, each node itself is a server with 19 client, so therefore 20servers in the whole system.
Now I only read from Java book with code segments that teaches the server thread to wait for client connection, once connected, spin off a thread to handle that connection than reloop that segment for further client connectino.
My huge question lies at, how do I expand this, or build such a system from my machine?
Specific Requirement as stated by the Project Document:
1. There are 20 nodes in the system, numbered from 0 ~ 19. Each node executes on a different machine. (There are 50 machines set aside for this assignment, named xxx01.xxx.xxx~ xxx50.xxx.xxx)
2. There are reliable socket connections (TCP) betw. each pair of nodes. All messages are sent over these connections.
Trying my best to learn.
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this an acedemic problem, or do you have control over the architecture? If it is the latter, I'd suggest looking into URL=http://www.jxta.org/]JXTA[/URL], a peer-to-peer framework. There's been a lot of work on p2p architectures in recent years, mostly driven by MP3 downloading and the efforts to stamp it out. Grid computing is another up-and-coming buzzword that may describe what you are doing. It's really nothing complex. Every node has a "server" (as you understand it) on it. When a node needs more power, he somehow determines what the other nodes are (a central repository is easiest, but p2p has gotten away from that lately) and connects to other nodes as a "client". Simple, but depending on your requirements, it can get way more complex.
 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately it is an academic assignment, so I don't have power over the architecture....
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you describe your requirements a little more? It sounds a little like a chat or instant messaging kind of thing. Is that on the right track?
 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the instruction that were given:
---------------------------------------------------------------------------
Project 1: This Project is to implement causally ordered broadcasting.
Requirements:
1. There are 20 nodes in the system, numbered from 0 to 19. Each node executes on a different machine. You can choose the machines from the fifty machines set aside for network programming (xxx01.xxx.edu ~ xxx50.xxx.edu)
2. There are reliable socket connections (TCP) between each pair of nodes. All message are sent over these connection.
3. Each node repeatedly goes through the following sequence of operations until each node has sent 1,000 messages. In case of broadcast, sent 1 copy to all other nodes count as 1 message:
(a) Wait for a random period of time between [2000,4000]ms before sending a message.
(b) The message contains actual clock value of the sending process when it decides to send the message. Obtain the value with a system call.
(c) When a node receives a message, the node wait a random period of time ([50,100]ms) before make the delivery decision.
4. Once all node finishes sending 1000msg, it sends a 'completion notification' to node 0.
5. Node 0 brings the entire distributed computation to an end once it has received all 'completion notification' from all the nodes, including itself.
---------------------------------------------------------------------------
To me it seems the hardest part is setting up the system of 20nodes... The class is Advanced Operating Systems so we're dealing with distributed systems, but we never really talk about how to set them up.
Any idea or suggestion? I'm sorry to be such clueless myself =(
ps. our school server does not support multicast, therefore, a broadcast simply means unicast to every other nodes.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to look into multi-casting.
 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you help! But can you be more specific? What about multi-cast....? And how does the use of that can help me set the system up?
Sorry for all the question.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem. Normally when you set up a socket between a client and a server, it's a direct communication. For example, computer 192.168.01 contacting 192.168.0.2 on port 30. The client has to have prior knowledge of the address of the server it's connecting to. This of course is not what you want because it won't scale well. If you change the IP on one computer, you'll have to update its IP address on EVERY computer in your group. Yikes! This is where multi-casting comes into play.
What you can do with multi-casting is have everyone broadcast themselves to anyone on the network listening on a multicast socket for a multicast address. So every computer listening on such a socket will get ALL the broadcasts, regardless of whether they knew of the computer beforehand. As well, the computer that is doing the broadcasting requires NO knowledge of who's listening - it'll reach them anyways! (think of it like a radio station - it doesn't need to know where your radio is for it to get the broadcast to you. And you need no knowledge of the physical location of the radio station, you just need to know the frequency to listen on)
Check out java.net.MulticastSocket.
One bit of "watch out." If you're using Windows and you're testing this on one computer (for dev. purposes), you won't get true multicasting unless you buy a piece of loopback hardware. It's a stupid design problem with MS's looback address. If you're on a network, then you'll have no problem with this.
[ February 01, 2004: Message edited by: Robert Paris ]
 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really thanks for the previous post, the radio was a great analogy for my part. I will look more into Multicasting.
However, 1 question, it is told that we are to telnet to our school servers, such as apache.server.edu, and from there we compile and execute our programs. It is also told that our server DOES NOT support multicast, and if that's the case, does the above method still works? The teacher said for the case at hand, a broadcast is a unicast to all nodes.
Our server machine runs Unix...thats about as much as I know.
Just trying to clarify, Thanks.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One option is to make each node aware of all the other nodes. This is a brute force approach, and not very lovely, but it oughtta work. Maybe give each machine a text file with the 20 IP addresses.

You might put that in your own words and see if it's what your instructor is looking for. One problem not solved here is starting up. It may take a few minutes to go to each machine and start the server, and you don't want any of them to start broadcasting before all the others are ready. Maybe start node 0 last, and have it broadcast a 'start' message to all the others?
 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thanks first for the reply! I have pictured (sort of) some bruteforce approach simliar to this one... But haven't be able to get a pseudocode out, so many thanks! I think the idea is definately right, but again yea some question that bothers me is how to determine node 0 from other nodes...(b/c node 0 has to act as a controller node, kind of, for starting and ending computation). Maybe I have to hardcode it in or...?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was imagining Node 0 is the first in the list. All nodes would have identical code, but one would recognize that the first entry in the list is its own IP address and act as Node 0.
This sounds like it could be a pretty involved project, and hard to test with all those nodes. Keep us posted on how it goes!
 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, as I am implementing this project, I have a new question that arise:
When a node starts up as a server, it receives connections from clients. However, in my case, that particular server will also connect to others, acting as a client. Then, how do I check if I have already established a connection socket with the target host? (Because that host could previously connected to me as a client already)
My implementation is that I setup each node to run a ServerThread which repeatly accepts client socket. Meanwhile the node also runs a ClientThread which attempts to connect all other nodes. (Then I run this same code at all nodes)
Testing out with 3 nodes only right now. It runs fine except that I just realize am I creating redundant socket streams?
is what I am trying to ask clear? Sorry for being messy,
Jack
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think in this massive point-to-point model that's just what you're going to have. Each node is running server functions and must open a server port. Each node is also running client functions that must connect to other servers. When acting as client you might want to connect, send and disconnect so you don't have the whole swarm holding all 20*19 client connections open all the time.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!