Re: Socket Client , abnormal behavior when sending byte
From: Jon A. Cruz (jon_at_joncruz.org)
Date: 02/28/04
- Next message: Jon A. Cruz: "Re: get Variable's name on runtime."
- Previous message: Ricardo: "Re: Printing problem"
- In reply to: Max: "Re: Socket Client , abnormal behavior when sending byte"
- Next in thread: Max: "Re: Socket Client , abnormal behavior when sending byte"
- Reply: Max: "Re: Socket Client , abnormal behavior when sending byte"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Feb 2004 10:39:54 -0800
Max wrote:
>>1) Are you using UDP instead of TCP?
>
>
> // get the socket !
> Socket s= new Socket("127.0.0.1",5000);
>
> // get the outputstream
> OutputStream myO = s.getOutputStream();
>
> // send the first 10 KByte and wait 1second
> myO.write(50_kb_total_stream,0,10*1024);
> myThread.sleep(1000);
Ooohhh. That's bad.
sleep() is a static method that operates on whatever the current thread
happens to be.
Instead of
myThread.sleep(1000);
use
Thread.sleep(1000);
Otherwise you're liable to get confused about your threading.
>
> // send the next 10KByte and wait 1 second
> myO.write(50_kb_total_stream,10*1024,20*1024);
Aha. That's the main problem that Joe pointed out.
Check the Java docs
http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html
> void write(byte[] b, int off, int len)
> Writes len bytes from the specified byte array starting at offset off
> to this output stream.
So as you're increasing the offset, you're also increasing the size.
- Next message: Jon A. Cruz: "Re: get Variable's name on runtime."
- Previous message: Ricardo: "Re: Printing problem"
- In reply to: Max: "Re: Socket Client , abnormal behavior when sending byte"
- Next in thread: Max: "Re: Socket Client , abnormal behavior when sending byte"
- Reply: Max: "Re: Socket Client , abnormal behavior when sending byte"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|