Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved] Hanging networking code? (Client I/O Init)  (Read 1665 times)
0 Members and 1 Guest are viewing this topic.
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Posted 2014-10-18 04:42:26 »

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:
1  
2  
3  
GNetClient -> (1/3) Streams initialized in 0ms.
GNetClient -> (2/3) Streams initialized in 0ms.
GNetClient -> (2/3) Streams initialized in 2251ms.

Initialization code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
// 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 ^__^

Checkout my new easy to use java networking library: GNetLib
Offline Stranger
« Reply #1 - Posted 2014-10-18 06:03:09 »

I think your init code should contain something like this:
Server:
1  
2  
3  
4  
ServerSocket serverSocket = new ServerSocket(portNumber);
    Socket clientSocket = serverSocket.accept();
    bos = new BufferedOutputStream(clientSocket.getOutputStream());
    bis = new BufferedInputStream(clientSocket.getInputStream());

Client:
1  
2  
3  
Socket socket = new Socket(hostName, portNumber);
    out = new BufferedOutputStream(socket.getOutputStream());
    in = new BufferedInputStream(socket.getInputStream());

Anton
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #2 - Posted 2014-10-18 06:14:35 »

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

Thanks alot, initializes almost instantly now ^__^
(No server-sided changes)

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

- Yay!! awkward... but yay Grin
 

Checkout my new easy to use java networking library: GNetLib
Pages: [1]
  ignore  |  Print  
 
 

 
mercenarius (4 views)
2020-06-04 19:26:01

mercenarius (2 views)
2020-06-04 19:13:43

Riven (850 views)
2019-09-04 15:33:17

hadezbladez (5834 views)
2018-11-16 13:46:03

hadezbladez (2635 views)
2018-11-16 13:41:33

hadezbladez (6251 views)
2018-11-16 13:35:35

hadezbladez (1504 views)
2018-11-16 13:32:03

EgonOlsen (4739 views)
2018-06-10 19:43:48

EgonOlsen (5797 views)
2018-06-10 19:43:44

EgonOlsen (3282 views)
2018-06-10 19:43:20
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!