Networking
if anyone can give me a strategy (I don t need it spelled out to me just general "I used this
function type help) I d really appreciate it.
Answer 1: I ve found the only way to unblock a (Socket) read blocking thread is to close() the
socket from another thread. That ll throw an IOException in the read() call.
  
Michiel
Answer 2: Another method that seems to work is to set a socket timeout to something
moderately short (like 10 seconds). The blocked read will throw an exception when the
timeout occurs. Then the thread can inspect the state of a variable (set by another thread
calling an appropriate method) to see if it should terminate.
This approach also makes it trivial to implement a longer inactivity timeout if desired and gives
the network thread an opportunity to do some maintenance work if it wants.
  
Peter
Q: I get the impression that only read operations from a Sockets InputStream throw an
Exception if the opposite Socket has closed the socket. Writing to the Socket s outputStream
works fine...
Is there a way to detect if what I write into a Socket s outputstream is actually still being
received by the other side? 
Or will I have to check that I actually get a response via the InputStream, and if not, try to open
a new Socket and resend the request again?
Answer: You can try calling flush() after writing the output, but there s no guarantee that you ll
get an immediate exception. The underlying TCP/IP software may go through timeout and
retry logic before giving up. 
That s probably why you ll usually find out about a broken socket when waiting to read. You
should rewrite client so that it sends a request and waits for a response. If it doesn t get a
response, it should try to make a new connection and do the request/response thing again. 
If it doesn t work the second time, it should give up for the time being. Perhaps it really makes
sense that one has to verify  by hand  that requests go through.
  
Duane Morse
 Q: ... I imagine, I ll have to cut my file into small datagrams.
I just made a little chat program (client and server) and I would like to add the possibility to
transfer files.
The client and the server are communicating with TCP/IP using a socket.
I imagine, I ll have to cut my file into small datagrams. Is it necessary ? Has someone an idea
or a link to source code of such a function ??
Answer: No. If you were using UDP/IP (DatagramSocket and friends) then it would need to be
split up. The point of TCP is to avoid this need. Simple send the entire file in a stream.
(c)1999, 2000, 2001. JavaFAQ.nu. All rights reserved worldwide.
This document is free for distribution, you can send it to everybody who is interested in Java.
This document can not be changed, either in whole or in part
without the express written permission of the publisher.
All questions please 
mailto:info@javafaq.nu
file:///F|/a_jsite/350_tips/networking.htm (4 of 4) [2001 07 08 11:24:57]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved