Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: Socket IO
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 15975 of 16085
Post > Topic >>

Re: Socket IO

by EJP <esmond.not.pitt@[EMAIL PROTECTED] > Apr 16, 2008 at 11:50 AM

Chase Preuninger wrote:
> if(s.getInetAddress().getHostAddress().equalsIgnoreCase(validIP))

I suggest that this test is failing, so you are writing nothing and 
immediately closing the socket, hence the immediate read() returning -1 
at the receiver. I would print a trace if this test fails, as surely you 
want to know about invalid source addresses, as well as debug this
problem.

>                 s.close();

Wrong. You should always close the outermost output stream of the 
socket, and closing a socket or its output stream or its input stream 
closes the other two.

>             while(!s.isClosed() && (b = in.read()) != -1)

The s.isClosed() test here is pointless, unless you have another thread 
that might close the socket. It won't tell you when you have reached 
EOF. read() returning -1 tells you that.

>                     s.close();

See above. Close the output stream only.




 3 Posts in Topic:
Socket IO
Chase Preuninger <chas  2008-04-15 15:09:53 
Re: Socket IO
=?ISO-8859-1?Q?Arne_Vajh=  2008-04-15 22:05:25 
Re: Socket IO
EJP <esmond.not.pitt@[  2008-04-16 11:50:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 3:21:48 CDT 2008.