Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java Socket and Wireshark Help
New Posts  All Forums:Forum Nav:

Java Socket and Wireshark Help - Page 2

post #11 of 25
Thread Starter 
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();
    }
}

Edited by Lyoko - 6/28/08 at 8:50pm
post #12 of 25
BufferedReader's readLine method might be the problem

Quote:
Read a line of text. A line is considered to be terminated by any one of a line feed ('n'), a carriage return ('r'), or a carriage return followed immediately by a linefeed.
Link

It would seem that it's waiting for a newline to be sent.
Edited by rabidgnome229 - 6/28/08 at 8:59pm
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #13 of 25
Thread Starter 
Quote:
Originally Posted by rabidgnome229 View Post
BufferedReader's readLine method might be the problem



It would seem that it's waiting for a newline to be sent.
Well, I am waiting for a response from the server but not a new line! So that probably is one of the problems. Going to just read().

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());
   //}

Edited by Lyoko - 6/28/08 at 9:33pm
post #14 of 25
Thread Starter 
By the way, how can I get the a unix timestamp of the current time in java? Thanks!
post #15 of 25
Thread Starter 
Ok. It's writing now but it's still not the values I want.

post #16 of 25
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 }
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #17 of 25
Thread Starter 
Quote:
Originally Posted by rabidgnome229 View Post
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 }
Trying with char array!
It worked!!!
Thanks again rabid!!!
Edited by Lyoko - 6/28/08 at 10:03pm
post #18 of 25
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.
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
3800x2 DFI NF4 SLI-D HD4850 2gb GSkill ZX 
Hard DriveOSMonitorPower
6+TB of insanity XP Pro L2410NM + DYLM24D6 Corsair 750TX 
CaseMouse
Rocketfish MX 510 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
3800x2 DFI NF4 SLI-D HD4850 2gb GSkill ZX 
Hard DriveOSMonitorPower
6+TB of insanity XP Pro L2410NM + DYLM24D6 Corsair 750TX 
CaseMouse
Rocketfish MX 510 
  hide details  
Reply
post #19 of 25
Thread Starter 
ok, thanks
post #20 of 25
Thread Starter 
Before the end of the method, how do I get a response from the server? Here's what I've thought up so far but it's not working:
Code:
while(in.ready()) {
    System.out.println(in.read());
    }
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java Socket and Wireshark Help