Client-Server, Threads, client error while online

Asked

Viewed 74 times

3

I’m developing an application cliente-servidor, the server has two threads (one in and another out) well-implemented.

I walk the server (all right), I walk the first client and I put it online (all right), I walk the second client and when I click online it gets blocked.

I tried to cycle:

for(int i = 0; i < 2; i++)

I noticed with this cycle that the first client also blocks when staying online, IE, the error of my project is here! Someone can help me?

Follows the code:

public PainelEstadoContacto(JanelaUtilizador janelaUtilizador) {
    this.janelaUtilizador=janelaUtilizador;

    botaoOnline= new JButton("ONLINE");
    botaoOnline.addActionListener(e -> {
        String nome = nomeUtilizador.getText();

        if(!nome.isEmpty()){
            this.mensagem = new Mensagem();
            this.mensagem.setAccao(Accao.ONLINE);
            this.mensagem.setNomeClienteEnviaMensagem(nome);

            this.socketCliente = new SocketCliente();
            this.socket = this.socketCliente.estabelecerLigacao();          

            new Thread(new ThreadCliente(this.socket)).start();                              }
        this.socketCliente.enviar(mensagem);

    });
  • 1

    When making the loop, the first one stays too, but isn’t it because another took the place? If there is the Synchronized block, it will not continue with just one anyway?

  • @Douglasgaldino yes I have the Synchronized block should continue with more than one account is strange

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.