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

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?

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