• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java RMI Multiple server/Single client

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I am fairly new to Java RMI and I have some questions regarding how a client can interact to particular server

I have developed a working program consist of 1 server and 1 client. I was asked to modify the program into multiple server and 1 client where 1 client send request to master server, then master server divide the task to several other sub server.
Below is the server code so far


Say client send message "A", "B", "C" to master server, then master server divide the message to 3 sub server receiving 1 letter each. Sub server 1 will return string "Sub server 1: Received Message A". The same goes to sub server 2 and 3.

My question is,
1. Is my approach on creating multiple server is correct (Code above)? Im creating multple server using different port with same Host. I am not sure if I am doing the right thing, but when i checked port listened using netstat in windows command, i do find all my registered port there. All with the same PID.
2. If my approach is correct, how exactly do I give particular message to particular sub server? Because for now, my client only connected to the master server using the (I am assuming this is what make the client connect to server)


For now I didn't include my client code yet because it is pretty long and the scenario I gave above is pretty much the simpler version of it.
I would like to have a clear view on how to achieve this. I tried googling around but I can't find any topic regarding this. Or maybe I just don't know the correct term for this kind of problem
Thanks if advanced
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ran Luer wrote:Hello. I am fairly new to Java RMI and I have some questions regarding how a client can interact to particular server

I have developed a working program consist of 1 server and 1 client. I was asked to modify the program into multiple server and 1 client where 1 client send request to master server, then master server divide the task to several other sub server.



Hi Ran, welcome to the Ranch!

I'm confused about whether the master server is supposed to send requests to the other sub servers, and then return the results to the client, or whether the clients are supposed to connect directly to the sub servers themselves. But from what you've written in your post, it looks to me like you have the same confusion. At the beginning of your post it looks like it's the former version, but by the time you get to the end of the post it looks like you're talking about changing the client software, which would be the latter version.

So to get your clear view on how to achieve your goal, I think it would be very helpful to consider what exactly the goal is. I know it sounds obvious, but there's no point in writing code when you don't know what the code is supposed to do. The hard part is to realize that you don't know.
 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh sorry i shoule've make it clear on my post.

The client are suppose to connect to master server then master server will connect to sub server and divide task. Sub server should return message to master server then master server will return the message from sub server to the client.
I hope this clear up the confusion. My apologize as English is not my native language.

Thanks
 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:[
Hi Ran, welcome to the Ranch!

I'm confused about whether the master server is supposed to send requests to the other sub servers, and then return the results to the client, or whether the clients are supposed to connect directly to the sub servers themselves. But from what you've written in your post, it looks to me like you have the same confusion. At the beginning of your post it looks like it's the former version, but by the time you get to the end of the post it looks like you're talking about changing the client software, which would be the latter version.

So to get your clear view on how to achieve your goal, I think it would be very helpful to consider what exactly the goal is. I know it sounds obvious, but there's no point in writing code when you don't know what the code is supposed to do. The hard part is to realize that you don't know.



I am sorry for the double post. I am new to the forum so I didn't know i cant delete my reply. Was going to quote you. Anyway, I hope my explaination clear up the confusion
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good, that's much simpler.

So... your master server is going to receive a request from a client, and it's going to handle that request by dividing it into several tasks. Then it's going to send each of those tasks as a request to a sub server, and finally it's going to take all of the responses to those requests and combine them into a response to be sent back to the original client.

Now, you already know how to deal with a client sending a request to a server and receiving a response. (Or if you don't know that yet, then pause a bit and make sure you do know it before going on.) That's the first part.

The second part is for the master server to split a request into several tasks. That's very context-dependent, by which I mean it depends very much on the nature of the request and the tasks it's supposed to be split into.

And the third part is for the master server to send a request to a sub server and receive the response. You already know how to do that; the master server just has to act as a client, and the sub server is a server. As I said, this is something you already understand.

Does that help?
 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Good, that's much simpler.

The second part is for the master server to split a request into several tasks. That's very context-dependent, by which I mean it depends very much on the nature of the request and the tasks it's supposed to be split into.



Yes this is the part where i am stuck at. I am able to split 1 task into 3 small part ( where in this situation ABC has been split into A, B, C). For now my server part has 3 source code which is interface source code, implementation source code(this is where i split task) and 1 source code that start the connection of master server and sub server ( the code above).

My problem is, I don't really know how to make master server interact with sub server (they're in different port but in the same host). I know sub server is successfully created but to send all the task is quite blur to me.

Previously i only have 1 server, so basically when client send request, the master server receive it then process it( string "Message has been receive: ABC") and then simply return it to client back.

I hope i explain it clearly. Thanks for taking your time to reply.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ran Luer wrote:My problem is, I don't really know how to make master server interact with sub server (they're in different port but in the same host). I know sub server is successfully created but to send all the task is quite blur to me.



Sure you do. The master server is acting as a client. The sub server is acting as a server. You already know how to write code for a client to communicate with a server.
 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Sure you do. The master server is acting as a client. The sub server is acting as a server. You already know how to write code for a client to communicate with a server.



Ohhh. I didnt know i can do that with server as well. So i assume i also will need interface and implementation method for all sub server as well?
I didnt know the solution is as simple as that. I didn't think outside of the box enough. Quite disappointed in myself haha
Thank you very much im going straight to my code now. I'll update anything here if I encounter any problem if thats okay.

Thanks again. Have a nice day!
 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. So I've successfully connect master server and sub server. Also, I manage to get message from sub server to client. Now, I would like to ask about multithreading.
So my sub server are suppose to use thread (based on how many the user want). Here is my code, it is working properly (able to use multithreading)


After checking the time taken, it seems that sometime time taken for 1 thread is shorter than 2 - 5 thread. And there are time when 1 is longer than 2 but is shorter than 3-5 (i hope you get what i mean) and rarely 5 is shorter than 1-4 thread.
Did i do something wrong in the code? I thought 5 thread will always take shorter time compare to 1-4 thread.

Thanks in advaced
p/s Should i create new topic just for this problem? or just continue it here
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ran Luer wrote:After checking the time taken, it seems that sometime time taken for 1 thread is shorter than 2 - 5 thread. And there are time when 1 is longer than 2 but is shorter than 3-5 (i hope you get what i mean) and rarely 5 is shorter than 1-4 thread.
Did i do something wrong in the code? I thought 5 thread will always take shorter time compare to 1-4 thread.



No; there is an overhead associated with using a thread, just for creating it and having the operating system deal with it. The more threads, the more overhead.

Should i create new topic just for this problem? or just continue it here



Well, for this post I'll just point out that line 34 is unnecessary. Just call join() on each of the threads you're waiting for, it doesn't matter whether the threads are alive or not. But otherwise, yes, start a new thread.
 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Well, for this post I'll just point out that line 34 is unnecessary. Just call join() on each of the threads you're waiting for, it doesn't matter whether the threads are alive or not. But otherwise, yes, start a new thread.



Thanks. I will start a new topic then
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Ran, just wanna ask. Do you have any full coding for this program?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

The OP hasn't posted for five months; you may not get a reply.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic