|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Java Socket and Wireshark Help
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#11 (permalink) |
|
Programmer
|
Code:
import java.io.*;
import java.net.*;
public class Main {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("CENSORED", PORT (CENSORED), InetAddress.getLocalHost(), LOCAL PORT (CENSORED));
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to host.");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) == null) {
out.write("010000006a".toCharArray());
System.out.println("echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}
Last edited by LyokoHaCk : 06-28-08 at 11:50 PM. |
|
|
|
|
|
#12 (permalink) | ||||||||||||||
|
Apple Doesn't Love You
|
BufferedReader's readLine method might be the problem
Quote:
It would seem that it's waiting for a newline to be sent.
Last edited by rabidgnome229 : 06-28-08 at 11:59 PM. |
||||||||||||||
|
|
|
|
#13 (permalink) | |
|
Programmer
|
Quote:
Ah, I understand what you're saying now. I changed it again.. It now runs immediately. Code:
//String userInput;
//while ((userInput = stdIn.readLine()) != null) {
out.write("010000006a".toCharArray());
//System.out.println("response ("+userInput+"): " + in.read());
//}
Last edited by LyokoHaCk : 06-29-08 at 12:33 AM. |
|
|
|
|
|
|
#16 (permalink) | |||||||||||||
|
Apple Doesn't Love You
|
You sent it the string "010000006a." Numbers in the ASCII character set are represented by the byte 0x3# where # is the digit. Lowercase letters start with 'a' at 0x61. You can view an ascii table here. You want to send the bytes { 0x01, 0x00, 0x00, 0x00, 0x6a }
|
|||||||||||||
|
|
|
|
#17 (permalink) | |
|
Programmer
|
Quote:
It worked!!! Thanks again rabid!!! Last edited by LyokoHaCk : 06-29-08 at 01:03 AM. |
|
|
|
|
|
|
#18 (permalink) | ||||||||||||
|
New to Overclock.net
|
System.currentTimeMillis() will give you the number of milliseconds since the epoch. IIRC, Unix timestamps are seconds since the epoch, so just do a conversion from there.
__________________
|
||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|