Re: [xSocket-develop] receiving data from server
Status: Inactive
Brought to you by:
grro
|
From: quan n. h. <hu...@gm...> - 2010-02-25 13:57:31
|
thanks
-Quan
On Thu, Feb 25, 2010 at 2:07 PM, Gregor Roth <gre...@gm...> wrote:
> Hi Quoa,
>
> yes the available() method is similar. And I also agree with Erin. You have
> to understand the protocol. Does the protocol use fixed length data records?
> or does it use leading length fileds? or delimiters? or ...?
>
> Gregor
>
>
>
>
> ----- Original Message -----
>
> From: quan nguyen huu
>
> Sent: 02/25/10 05:27 AM
>
> To: Erin Drummond, xso...@li...
>
> Subject: Re: [xSocket-develop] receiving data from server
>
>
>
> in java socket, InputStream.read() return the next byte of data, or -1
> if the end of the stream is reached. I used it to read data of each
> stream.
>
> InputStream in = sock.getInputStream();
>
> byte[] temp = new byte[100];
>
> // receive data
> int length = in.read(temp);
>
> & i think available() method here is similar.
>
> -Quan
>
>
>
> On Thu, Feb 25, 2010 at 10:57 AM, Erin Drummond <eri...@gm...> wrote:
>> In that case, your code seems like it will work if you know in advance
>> how many bytes you need to read. If you dont, I think you will need to
>> look at the protocol used by the vendor to see what denotes an
>> end-of-message and then use readBytesByDelimiter(). I cant think of
>> another way to read a whole message when the length isnt known in
>> advance.
>>
>> Of course I am by no means an expert, Gregor should be able to be more
>> helpful.
>>
>> Cheers,
>> Erin
>>
>> On Thu, Feb 25, 2010 at 4:50 PM, quan nguyen huu <hu...@gm...>
>> wrote:
>>> server side is handled by other vendor, i only develop client side to
>>> connect to it.
>>>
>>> java doc
>>>
>>> int available() throws IOException
>>> the number of available bytes, possibly zero, or -1 if the channel has
>>> reached end-of-stream
>>>
>>> -Quan
>>>
>>>
>>>
>>> On Thu, Feb 25, 2010 at 10:44 AM, Erin Drummond <eri...@gm...>
>>> wrote:
>>>> I personally havn't tried that, so I dont know if it works. Heres how I
>>>> do it:
>>>>
>>>> In my case, I have control over the server, so I append the delimiter
>>>> "__DELIMITER__" to the end of each message, then use
>>>> nbc.readBytesByDelimiter("__DELIMITER__") to get the whole message on
>>>> the client side.
>>>>
>>>> It works quite nicely, and results in a bit less code.
>>>>
>>>> On Thu, Feb 25, 2010 at 4:35 PM, quan nguyen huu <hu...@gm...>
>>>> wrote:
>>>>> i check doc again & found this code
>>>>>
>>>>> private int remaining = 0;
>>>>>
>>>>> ..
>>>>>
>>>>> int available = nbc.available();
>>>>>
>>>>> int lengthToRead = remaining;
>>>>> if (available > remaining) {
>>>>> lengthToRead = available;
>>>>> }
>>>>>
>>>>> byte[] message = nbc.readBytesByLength(lengthToRead);
>>>>>
>>>>> is it the right way?
>>>>>
>>>>> -Quan
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Feb 25, 2010 at 10:10 AM, quan nguyen huu <hu...@gm...>
>>>>> wrote:
>>>>>> hi,
>>>>>>
>>>>>> in client, i use readBytesBylength() to receive data from server:
>>>>>> nbc.readBytesByLength(200);
>>>>>>
>>>>>> but the problem is the message server send to client have different
>>>>>> lengths.
>>>>>> example: first, server send 20 bytes message, after server send 7
>>>>>> bytes message to client.
>>>>>> the client always seems to wait for receive full 200 bytes message to
>>>>>> process next step :|
>>>>>>
>>>>>> how to get instant message sent from server.
>>>>>>
>>>>>> thanks
>>>>>> -Quan
>>>>>>
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> Download Intel® Parallel Studio Eval
>>>>> Try the new software tools for yourself. Speed compiling, find bugs
>>>>> proactively, and fine-tune applications for parallel performance.
>>>>> See why Intel Parallel Studio got high marks during beta.
>>>>> http://p.sf.net/sfu/intel-sw-dev
>>>>> _______________________________________________
>>>>> xSocket-develop mailing list
>>>>> xSo...@li...
>>>>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>>>>
>>>>
>>>
>>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|