0

I have to make an university project that involves a client/server architecture.

There should be a server where a client can login and search or save some stuff.

What's the best way to implement a stuff like that?

I think it can be done using RMI or ServerSockets or even WebServices, but what's the easiest way to implement this project?

Using Web Sevrvices i think it can be troublesome the authentication/session handling, using ServerSockets i have done some tests where i pass some custom serialized objects, but It doesnt seem to me a good way to go.

Any help is appreciated

3 Answers 3

2

Since this is a project for university I will not post an solution, but give you an good direction.

The most basic Way (what may be a good thing for a university project, and for understanding th whole matter...) would be with the Server listening in his Mainthread on a ServerSocket for Requests to connect to the Server and then for every (correct) Request (you need to specify somehow what is correct in this case) starting a new Thread with a Socket connected to the Client. This Threads should be hosted in some sort of List or whatever in the Mainthread of the Server...

Update:

So if this Server provides different functionalities to its clients, which are of course methods in our Server Code, you can specify the Objects which are crated when a new Client connects (I'm calling these "ClientServerConnection" from now on, and which run in its own Thread) in the Way that the Server Object is passed to it, so if one of the "ClientServerConnection"s get a Request for whatever they can call the matching method on the Server-Object and give an according response to the client...

Here some pseudo-code:

in Server:

//request for Connection came in 
ClientServerConnection csc = new ClientServerConnection(this, "and everything you need, at least client IP for connecting the socket");
csc.run(); //running in its own thread, of cause ClientServerConnection should extend Thread
connectionList.add(csc); //a list of the connections the Server holds

in ClientServerConnection:

//A request to the use a functionality of the Server come in, in the easiest way you are sending a String, and than trying to match it here
if(recievedString=="doWhatever"){
Server server.doWhatever(); //calling the according method on the Server Object you passed by creation of the ClientServerConnection Object
//now return something to the client, according to whatever the Method did 
}else if(recievedString=="doSomethingElse"){
//same again, according to whatever the now requested method does
}else{
//the client requested something you do not provide, need some sort of handling here
}

Hope I got you right and this helps...

3
  • Agreed, you wil learn more on client / server software architecture by using ServerSocket / Socket
    – phsym
    Aug 24, 2012 at 9:43
  • This is similar to the idea i was testing, but how am i going to handle different functions (Save/Load/Search/ecc.)? I need to use the same serialized object for every function with different values? It scared me as a confusionary design
    – alessiop86
    Aug 24, 2012 at 10:39
  • ok, im not sure if im getting you right, but what i understand by now is that you have a server which provides different fuctionalities to the clients registered. i'll update the answer
    – nurgan
    Aug 24, 2012 at 11:09
0

'Easy' is a subjective thing, depending on what you already have experience on. If you have experience in Java related technologies, you could pick a tech stack like Servlets, JSP and JQuery, and use GAE to keep things simple from the 'troublesome' aspects you mentioned. GAE is a platform as a service so you woudnt have to worry about those things, as google takes care of the authentication, scaling etc. You can use GAE with PHP too, if you are into that.

0

I think RMI is the easiest solution since you define all your interfaces and don't have to care about the protocol used to communicate.

You can also use web service with SOAP which is also a RPC (remote procedure call ) interface.

But by using Socket and ServerSocket you will learn how to build a server / client software from scratch, which is very important to know (because this is the basics).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.