This is probably not the best forum for a Java socket problem ;-)
... when doing socket stuff I now always find an appropriate framework and use that, rather than do the really low level stuff myself as there are far better experts at such things.
Why not search the net for an open source framework there are several what about ApacheMina (plenty of others), get it working in that if you can't use open source for whatever reason, their source code is freely available and usually well written to give you some tips as to where your going wrong.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
subject: Java Socket buffering problem and nonblocking