[solved] Hanging networking code? (Client I/O Init)

Hey JGO, In my networking library it seems to be taking forever to initialize the clients input stream?
(Attempting to implement UDP to work with my TCP packet system)

The server initializes the clients I/O almost instantly, but client-sided it hangs for 2,200ms+?

NOTE: Server/Client I/O are initialized the same way, the client initialization just hangs for a few seconds…

Console output:


GNetClient -> (1/3) Streams initialized in 0ms.
GNetClient -> (2/3) Streams initialized in 0ms.
GNetClient -> (2/3) Streams initialized in 2251ms.

Initialization code:


// Stage 1
bos = new BufferedOutputStream(serverSocket.getOutputStream());
bis = new BufferedInputStream(serverSocket.getInputStream());
			
// Stage 2
outputStream = new ObjectOutputStream(bos);
outputStream.flush();
			
// Stage 3
inputStream = new ObjectInputStream(bis); // OCCURS ON THIS LINE

Does anyone know why this is happening?

  • Thanks, if you need more info please ask :slight_smile:

I think your init code should contain something like this:
Server:

ServerSocket serverSocket = new ServerSocket(portNumber);
    Socket clientSocket = serverSocket.accept();
    bos = new BufferedOutputStream(clientSocket.getOutputStream());
    bis = new BufferedInputStream(clientSocket.getInputStream());

Client:

Socket socket = new Socket(hostName, portNumber);
    out = new BufferedOutputStream(socket.getOutputStream());
    in = new BufferedInputStream(socket.getInputStream());


inputStream = new ObjectInputStream(serverSocket.getInputStream());

Thanks alot, initializes almost instantly now :slight_smile:
(No server-sided changes)

Was bugging me why it would randomly pause there for a while lol…

  • Yay!! awkward… but yay ;D