Results 1 to 7 of 7
  1. #1
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Unhappy Communication Lag :(

    Hi:)

    I managed to connect two pcs using the ObjectInput/Output stream though I can send data over the socket there is a communication lag. and the thing that makes me suspect its a bug is that Its consistent. It keeps skipping every other message.

    Take for example I send the message the sequence of messages:

    * Hello (1)
    * How are you? (2)
    * What is new? (3)
    *Where are you now? (4)
    * I see..(5)


    Then only(1) + (3) + (5) would show up on the other screen...

    I have read about sockets and its all thesame information over and over again...and I knwo I am writting it exactly thesame.

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    Are you using flush()? Streams of all sorts have buffers, and they tend not to write until the buffer is filled. flush() forces the write.

  3. #3
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    yeah, I tried using flush()..its still thesame problem.

    Also I think I should mention that it is a thread that listens and writes the messages to, while another thread that handles the connection is running too. Would it happen to be because the Operating system is switching between the threads and misses some inputs?

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    No, not by itself. The lag sounds like a time out. Look at the API for your streams. It sounds like the first transmit gets through, and then the second one fails somehow, which leads to a reset and starts the process over. You may have to create a new ObjectInput/OutputStream after each use, or reset them. Again, read the API carefully.

  5. #5
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    Thanks alot , I would try that :) somehow I have a feeling it would work..

  6. #6
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    @Steve11235: I tried but it didn't work ....it sparked an error.

    Though there is something that also made me convinced that its a mistake from me, because it i clicked a button to send a message to the other screen and each time I did it printed an error on the screen ,showing that it not a sync problem. would try reading up...

  7. #7
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    Alhamdulillah....

    I finally got whats wrong. it was my mistake all along...

    I used to have this code ...
    Java Code:
    try
    {
    while(cs.isConnected())
    {
    if(in.readObject()!=null)
    addStatus( in.readObject().toString());
    }
    }catch(Exception e)
    {
    //exception code
    }
    it turns out the "if" that i was using to dodge null pointer exception was the problem, I just used the try and catch inside the loop directly on the code and it worked out...

    ... :)

Similar Threads

  1. UDP Communication
    By ls_venkat in forum Networking
    Replies: 0
    Last Post: 10-15-2009, 06:47 AM
  2. Communication to PC
    By Dan_68c in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 09-30-2009, 05:01 PM
  3. Communication between two Jars
    By Gijava in forum Advanced Java
    Replies: 1
    Last Post: 06-26-2009, 05:59 PM
  4. Jar and War communication in an Ear
    By madanmohanp in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2008, 02:39 PM
  5. Communication with c++
    By mathias in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 07:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •