Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since this is a project for university I will not post an solution, but give you an good direction.</p> <p>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...</p> <p>Update:</p> <p>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...</p> <p>Here some pseudo-code:</p> <p>in Server:</p> <pre><code>//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 </code></pre> <p>in ClientServerConnection:</p> <pre><code>//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 } </code></pre> <p>Hope I got you right and this helps...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload