Old tcp server client game

Asked

Viewed 684 times

0

I’m using the netbeans, and the program and what is on this link: Rooster Game / Old Game with Application Level Protocol

First I run the server says : server is running then run the client: and error appears on lines 28 and 187 but does not say what kind of error is, the lines are these :

try
    {
        server = new ServerSocket(5000,2);  // <- linha 28 erro !
    }

and the other mistake is this:

public static void main( String args[] ) 
{
    JFrame.setDefaultLookAndFeelDecorated(true);
    TicTacToeServerProtocolo game = new TicTacToeServerProtocolo(); // <- erro 187 nesta linha !!
    game.execute();
}

Both errors are from the program "Tictactoeclientprotocol.java"

Correct me if I’m doing something wrong. The game in question is the "Tic-tac-toe" as it is on the link I provided from this site also, it is an equal issue but related to notepadd++ but the objective is the same namely to run the server and the client at the same time (old game).

I know this code works (Tictactoe) because I saw it work on a friend of mine who gave me this code. He also used netbeans.

In the output "Output" this message appears exactly:

run:

java.net.BindException: Address already in use: JVM_Bind
    at java.net.DualStackPlainSocketImpl.bind0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:382)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
    at java.net.ServerSocket.bind(ServerSocket.java:375)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at java.net.ServerSocket.<init>(ServerSocket.java:181)
    at TicTacToeServerProtocolo.<init>(TicTacToeServerProtocolo.java:28)
    at TicTacToeServerProtocolo.main(TicTacToeServerProtocolo.java:187)

Java Result: 1

BUILD SUCCESSFUL (total time: 0 seconds)

1 answer

1

That mistake of Address already in use: Jvm_bind means you already have some application running on that port, you need to delete this application or change its port from 5000 to another higher value.

The higher, the lower the chance of being used.

To find who is using this door can do so:

Windows

  1. Execute resmon.exe

inserir a descrição da imagem aqui

  1. Networks Tab > Listening Ports

inserir a descrição da imagem aqui

Linux

netstat -tulpn

  • I already changed the ports to values 6000,9000 etc, and changed the port on the client and server, only changed two lines, only the port, I put equal port on the client and the server. The same mistake appears. But in netbeans running the client, you can’t change the port, I can change the port code, but when I want to open another client, running it goes to the same port I indicated, I think the two clients should be in different ports, but correct if I’m wrong.

  • The wrong line is in your ServerSocket precisely for the reason I explained above, you need to run it on another port and thus the customer connect on that same port.

  • @insyspower You are not running new Tictactoeserverprotocolo() more than once when door change?

  • I got it now! My mistake was to run Tictactoeserverprotocolo.java, but then there is that error, I have to make the folder pruning Tictactoeprotocol that contains all the files.

Browser other questions tagged

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