Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] java socket

Started by Kaze Apr 24, 2006 at 11:19 PM 3 replies 1.3k views
Original Post
Kaze
Kaze
in java when using a socket with tcp/ip how to you detect when messages arnt reaching the other side
Vasialek
Vasialek
Hello

As I know, in TCP/IP you got succesful ACK from first gateway. I guess, you need to impelemnt new protocol

Lekha
LizardCPP
LizardCPP
The TCP protocol guarantees that messages are delivierd. So there is no need to check if a message reaches the destination. What can ahppen though is that the connection goes down and that is deteched by a exception when trying to read/write to a socket.

Lizard
Vasialek
Vasialek
Sorry, I mistekened :( I thought you intention was to know the time when packet REACHES destination.

So in this case use PrintWriter.checkError(). Uncomment out.close() to see error :)

try		{			Socket s = new Socket( "www.google.com", 80 );			OutputStream outS = s.getOutputStream();			PrintWriter out = new PrintWriter( new OutputStreamWriter( outS ), true );						out.print("GET");			if( out.checkError() )				System.out.println("First packet FAILED!");			else				System.out.println("First packet is OK!");			//			out.close();			out.println(" / HTTP/1.0\r\n\r\n");			if( out.checkError() )				System.out.println("Second packet FAILED!");			else				System.out.println("Second packet is OK");			out.close();			s.close();		} catch (Exception ex)		{			ex.printStackTrace();		}


Lekha
Kaze
Kaze
thank you, .checkError() worked perfectly

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.