Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Object Stream Hanging...

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Location
    USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Object Stream Hanging...

    Hey Guys,

    I've made programs that use ObjectInput/ObjectOutputStreams across Socket Connections to send Serialized Objects across the line before, but for some reason with this latest program I'm working on the connection is just hanging when it should be establishing these streams.

    Here's the code on the Server Side:
    private final boolean setup()
        {
            //Setup Input Streams
            try{
                ois = new ObjectInputStream(socket.getInputStream()); // <- Hanging Here
            }catch(Exception e){
                e.printStackTrace();
                return false;
            }
            //Setup Output Streams
            try{
                oos = new ObjectOutputStream(socket.getOutputStream());
            }catch(Exception e){
                e.printStackTrace();
                return false;
            }
            return true;
        }

    And the Client Side (Essentially the Same):
    private final boolean setup()
        {
            //Attempt Connection
            try{
                socket = new Socket(serverName, PORT);
            }catch(Exception e){
                e.printStackTrace();
                return false;
            }
            //Setup Streams
            // - Input
            try{
                ois = new ObjectInputStream(socket.getInputStream()); <- Hanging Here
            }catch(Exception e){
                e.printStackTrace();
                return false;
            }
            // - Output
            try{
                oos = new ObjectOutputStream(socket.getOutputStream());
            }catch(Exception e){
                e.printStackTrace();
                return false;
            }
            //Return
            return true;
        }

    If someone could help me out with this I'd appreciate it 'cause I can't figure out for the life of me what's wrong. The code seems right, and when I run both programs the two connect to one another, they just hang when they should be establishing those object streams.

    Thanks!
    ... Ellipsis ...
    Java | C/C++ | x86 Assembly | Python
    HTML | PHP | CSS | Flash Actionscript


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,308
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Object Stream Hanging...

    I'm a bit rusty when it comes to programming sockets, but could they be hanging because each tries to first get the Input stream of the other, which hangs while waiting for the other to create the OutputStream? Try swapping the orientation (in each case, get the outputstream first).

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Location
    USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Object Stream Hanging...

    Yeah I figured it out. For some reason you have to establish the output streams before the input streams. Now it works perfectly.

    Thanks for the help!
    ... Ellipsis ...
    Java | C/C++ | x86 Assembly | Python
    HTML | PHP | CSS | Flash Actionscript

Similar Threads

  1. UTF - 8 / Byte Stream
    By JavaCODER in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 16th, 2010, 02:26 PM
  2. Stream Tokenizer
    By x3rubiachica3x in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 12th, 2010, 01:05 PM
  3. url input stream returning blank
    By yo99 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: June 2nd, 2010, 08:14 PM
  4. 2D Object makes my object smaller, Why?
    By MassiveResponse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2010, 02:33 PM
  5. Client input Stream
    By gisler in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 19th, 2009, 08:30 PM