DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    jenny Guest

    Time-out sockets?!?!


    I hope someone might be able to help me with this. I have a problem
    concerning java and sockets. I'm trying to do a "mySocket.receive()" (multicastsocket)
    in a client. The client is waiting for messages (datagram packets) to be
    sent from servers to the client. I want the client to listen for messages
    only for a short while and then do a time-out after about a minute.
    I have two problems here. The client gets stuck on the ".receive" call
    when no servers at all send messages. Not good. But if one server sends a
    message it is received successfully.
    The second problem is that I don't
    know how to do the time-out in the client. Perhaps with a thread?! In that
    case, is it possible to use the same datagram packet in all message
    receivings or do I have to create a new one every time?!?!

    I am very grateful for any answers!!!

    Best regards
    / jenny

  2. #2
    Paul Clapham Guest

    Re: Time-out sockets?!?!

    If you want the receive() method to time out after X seconds, you need to
    call "setSoTimeout(X * 1000)".

    PC2

    "jenny" <jennyjava@hotmail.com> wrote in message
    news:3c47b302$1@147.208.176.211...
    >
    > I hope someone might be able to help me with this. I have a problem
    > concerning java and sockets. I'm trying to do a "mySocket.receive()"

    (multicastsocket)
    > in a client. The client is waiting for messages (datagram packets) to be
    > sent from servers to the client. I want the client to listen for messages
    > only for a short while and then do a time-out after about a minute.
    > I have two problems here. The client gets stuck on the ".receive" call
    > when no servers at all send messages. Not good. But if one server sends a
    > message it is received successfully.
    > The second problem is that I don't
    > know how to do the time-out in the client. Perhaps with a thread?! In that
    > case, is it possible to use the same datagram packet in all message
    > receivings or do I have to create a new one every time?!?!
    >
    > I am very grateful for any answers!!!
    >
    > Best regards
    > / jenny




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links