Note that there are some explanatory texts on larger screens.

plurals
  1. POClient-server application socket problem
    text
    copied!<p>I am currently developing a client-server application and I have this problem: I want to create a different class instance depending on what the connected socket sends, but it only creates the first instance then it stucks. Here is some piece of code:</p> <pre><code> Socket clientSocket = null; ServerSocket server = null; String buff = null; transfer tr = null; colectieClienti clienti = new colectieClienti(); </code></pre> <p>And:</p> <pre><code>while (true) { try { clientSocket = server.accept(); buff = (new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))).readLine(); if (buff.equals("client")) { (colectieClienti.useri[colectieClienti.nrUseri++] = new clientThread(clientSocket, stmt)).start(); } else { tr = new transfer(clientSocket); tr.start(); } } catch (IOException ex) { System.out.println(ex); } } </code></pre> <p>I have to mention that <code>clientThread</code> is a class that extends <code>Thread</code> and communicates with a GUI, and <code>transfer</code> is a class that only send some files from client to server. The logic is something like this: In the GUI the user connects to the server, so it is created a new instance of <code>clientThread</code> and after this, when the user press a button it creates a new socket (on the client side and send a message to the server, something like "I want to create a new instance of <code>transfer</code> class, which is done by the <code>buff</code>) and receive the data. But it only creates the <code>clientThread</code> instance and then it stucks. Can anyone help me?</p> <p>LE: This is the constructor of <code>clientThread</code></p> <pre><code> public clientThread(Socket socket, Statement statement) { comunicare = socket; try { oStream = comunicare.getOutputStream(); is = new BufferedReader(new InputStreamReader(comunicare.getInputStream())); os = new PrintStream(oStream); } catch (IOException ex) { System.out.println(ex); } this.statement = statement; } </code></pre>
 

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