title: Java desktop client nodejs server using socketio, socket not connected
body: <p>So i have a javafx application , who i use for CRUD of client, on mode &quot;connected&quot; i need to send data on the server, offline , i register the data in a JSONfile</p>
  <p>When i use the controller ClientSocket (there is the run button that you can press), it shows that socket is connected , but when i launch the same code in the controller Controller (CRUD) the socket is not connected , no response from the node server</p>
  <p>Node.JS</p>
  <pre><code>const express = require('express')
  const app = express()
  const server = require('http').createServer(app)
  const io = require('socket.io') (server)
  const bodyParser = require('body-parser')
  const apiRouter = require('./router').router
  const port = 7777
  const path = require('path')
  
  app.get('/', (req, res) =&gt; {
    /*res.send('Hello Team7!!')*/
    res.sendFile('index.html',{ root : path.join(__dirname, '/')})
  })
  
  app.use(bodyParser.urlencoded({ extended: true }))
  app.use(bodyParser.json())
  
  app.use('/api/', apiRouter)
  
  io.on(&quot;connection&quot;, (socket) =&gt; {
    console.log('a user connected');
  
    socket.emit('hello','hello world')
  
    socket.on(&quot;hello&quot;, (arg,arg1,arg2) =&gt; {
      console.log(arg)
      console.log(arg1)
      console.log(arg2)
    })
  
    socket.on(&quot;essai_connect&quot;, (socket) =&gt; {
          console.log(&quot;user is really connected&quot;)
    })
  })
  </code></pre>
  <p>ClientSocket (Where the socket connection work, ie java client is launched)</p>
  <pre><code>public class ClientSocket {
  
      public static void main(String[] args) throws IOException, URISyntaxException {
  
          URI uri = URI.create(&quot;http://localhost:7777&quot;);
          IO.Options options = new IO.Options().builder().build();
          Socket socket = IO.socket(uri,options);
          socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
              @Override
              public void call(Object... args) {
                  System.out.println(&quot;socket connected&quot;);
                  System.out.println(socket.connected());
                  socket.emit(&quot;hello&quot;,1,&quot;2&quot;,&quot;Jo&quot;);
              }
          });
          socket.open();
  }
  </code></pre>
  <p>Controller (CRUD) where the socket client doesn't lauch at all</p>
  <pre><code>public void insertClient(ActionEvent event) throws IOException {
  
          String fileName = &quot;C:/Users/Dewei/IdeaProjects/ProjetClient/src/sample/client.json&quot;;
          File file = new File(fileName);
          if (nom.getText().isEmpty() || adresse.getText().isEmpty() || solde.getText().isEmpty())
          {
              System.out.println(&quot;Entrer les données&quot;);
          }
          else
          {
              URI uri = URI.create(&quot;http://localhost:7777&quot;);
              IO.Options options = new IO.Options().builder().build();
              Socket socket = IO.socket(uri,options);
              socket.on(&quot;essai_connect&quot;, new Emitter.Listener() {
                  @Override
                  public void call(Object... args) {
                      System.out.println(socket.connected()); // true
                  }
              });
              System.out.println(&quot;Socket&quot;);
              System.out.println(socket.connected());
              if (socket.connected())
              {
                  socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
                      @Override
                      public void call(Object... args) {
                          Integer soldeInt = Integer.parseInt(solde.getText());
                          socket.emit(&quot;ajout&quot;, &quot;1&quot;,nom.getText(),adresse.getText(),soldeInt);
                          socket.close();
                          System.out.println(args[0]);
                          ObservableList&lt;Client&gt; clientList = null;
                          try {
                              clientList = ClientDao.getAllRecords();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                          populateTable(clientList);
                          clean();
                      }
                  });
                  socket.open();
              }
              else
              {
                  /*Integer soldeInt = Integer.parseInt(solde.getText());
                  ClientDao.insertClient(1,nom.getText(),adresse.getText(),soldeInt);
                  ObservableList&lt;Client&gt; clientList = ClientDao.getAllRecords();
                  populateTable(clientList);
                  clean();*/
              }
          }
      }
  </code></pre>
  <p>}}</p>
  <p>please help guys , i am running out of ideas</p>