Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 06-28-08   #11 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,995

Rep: 74 LyokoHaCk is acknowledged by some
Unique Rep: 0
FAQs Submitted: 1
Trader Rating: 2
Default

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.
LyokoHaCk is online now   Reply With Quote
Old 06-28-08   #12 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,952
Blog Entries: 1

Rep: 560 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 1
FAQs Submitted: 6
Trader Rating: 5
Default

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.
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw

Last edited by rabidgnome229 : 06-28-08 at 11:59 PM.
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 06-28-08   #13 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,995

Rep: 74 LyokoHaCk is acknowledged by some
Unique Rep: 0
FAQs Submitted: 1
Trader Rating: 2
Default

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

Last edited by LyokoHaCk : 06-29-08 at 12:33 AM.
LyokoHaCk is online now   Reply With Quote
Old 06-29-08   #14 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,995

Rep: 74 LyokoHaCk is acknowledged by some
Unique Rep: 0
FAQs Submitted: 1
Trader Rating: 2
Default

By the way, how can I get the a unix timestamp of the current time in java? Thanks!
LyokoHaCk is online now   Reply With Quote
Old 06-29-08   #15 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,995

Rep: 74 LyokoHaCk is acknowledged by some
Unique Rep: 0
FAQs Submitted: 1
Trader Rating: 2
Default

Ok. It's writing now but it's still not the values I want.
Attached Thumbnails
java-socket-wireshark-help-ss2.bmp  
LyokoHaCk is online now   Reply With Quote
Old 06-29-08   #16 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,952
Blog Entries: 1

Rep: 560 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 1
FAQs Submitted: 6
Trader Rating: 5
Default

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 }
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 06-29-08   #17 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,995

Rep: 74 LyokoHaCk is acknowledged by some
Unique Rep: 0
FAQs Submitted: 1
Trader Rating: 2
Default

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!!!

Last edited by LyokoHaCk : 06-29-08 at 01:03 AM.
LyokoHaCk is online now   Reply With Quote
Old 06-29-08   #18 (permalink)
New to Overclock.net
 
amd ati

Join Date: Jun 2008
Location: Dallas,TX
Posts: 413

Rep: 68 heretic is acknowledged by some
Unique Rep: 0
Trader Rating: 1
Default

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.
__________________
System: My System
CPU
3800x2
Motherboard
DFI NF4 SLI-D
Memory
2gb GSkill ZX
Graphics Card
HD4850
Hard Drive
6+TB of insanity
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 750TX
Case
Rocketfish
CPU cooling
TT Sonic Tower
OS
XP Pro
Monitor
L2410NM + DYLM24D6
heretic is offline   Reply With Quote
Old 06-29-08   #19 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,995

Rep: 74 LyokoHaCk is acknowledged by some
Unique Rep: 0
FAQs Submitted: 1
Trader Rating: 2
Default

ok, thanks
LyokoHaCk is online now   Reply With Quote
Old 06-29-08   #20 (permalink)
Programmer
 
LyokoHaCk's Avatar
 
amd nvidia

Join Date: Aug 2006
Location: United States Inc.
Posts: 1,995

Rep: 74 LyokoHaCk is acknowledged by some
Unique Rep: 0
FAQs Submitted: 1
Trader Rating: 2
Default

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());
    }
LyokoHaCk is online now   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 07:39 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.20653 seconds with 10 queries