Distributed computing] How to let a class act both a server and client?
I am imlementing a didtributed banking system.
There are 4 bank branchs need to communicate to each other ,get balance and transfer money from one branch to another, so they need to act both as a server and client?
I know how to write a program in a standard client communicates to server and server respond to cliemt but I have no idea how to let them both act as a server and client.
And if I use socket, the client (or server) will just send a stream to server, so how could the server (or client) know what's kind of operation he need to do?
Anyone know how to do it? Please help me.
You've got loads of ways you could implement this.
From your post, I'm assuming you're not going to use RMI.
If so, then it might be worth creating a little protocol for your system to use. For example, the first word use in the communication is the operation required, following by its details. For example:
The first command asks for the balance of the branch that the command is sent to. The second command requests the transfer £321.55 *to* the branch that the command is sent to. The third command requests the transfer of £21.32 *from* the branch tha the command is sent to.
If I use RMI, how should I do to let a class both act as a server and client?
If you haven't done RMI before I wouldn't recommend it to do this coursework - it takes a bit of getting used to. Sockets will do fine.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL