Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

java.net and getOutput/InputStream...

Name: Anonymous 2007-02-22 6:24 ID:CFOnodjP

well, i have a little problem. i need to send a simple server "hello?" and recieve instructions for a puzzle. thing is, i can't particularly get it to work. heres my code.

public class Puzzles{
    static Socket s = new Socket();
    static InetSocketAddress address = new InetSocketAddress(new String("hostname"), port);
   
    public static void main() throws IOException{
       
        s.connect(address);
       
        OutputStream out = s.getOutputStream();
        byte byteOut[] = new String("hello?").getBytes();
        out.write(byteOut);
       
        InputStream in = s.getInputStream();
        byte byteIn[] = new byte[6000];
        int bytesRead = in.read(byteIn);
       
        String response = new String(byteIn, 0, bytesRead);
        System.out.print(response);

    }

}

i took out the hostname and port in this post. i'm using Bluej to compile and run it, and, well i dont recieve an error message from Bluej, but the virtual machine window just prints out:

**connection timed out. Good-bye.

i'm dead positive i have the hostname and port correct (copy/pasted, and double checked.. multiple times)

im sure theres something wrong with my code, mainly with my output and input streams. any suggestions?

Name: Anonymous 2007-02-22 6:54 ID:CFOnodjP

fixed. needed s.shutdownOutput(); after out.write()

Name: Anonymous 2007-02-22 17:13 ID:5rY89H/x

Wow, I can't believe you are actually sending "hello?" That's the most inefficient thing I've ever seen. Just because you're writing a puzzle game where latency isn't an issue doesn't give you the right to waste bandwidth with crap protocols like that.

Name: Anonymous 2007-02-22 17:58 ID:08VHkhg9

>>1
 
Fails for using BlueJ

Name: Anonymous 2007-02-22 20:04 ID:A0w0K1qO

>>1

Fails for Java

Name: Anonymous 2007-02-23 2:33 ID:l02FQGPh

>>1
One word. The forced indentation of code. Thread over.

Name: Anonymous 2009-01-14 13:12

LISP

Name: Sgt.Kabuૅkiman䦂኉ 2012-05-28 22:49

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List