Home All Groups Group Topic Archive Search About

Best way to do a connection-oriented Send/Receive.

Author
26 Jan 2006 4:55 AM
Simon Says
Hi all,

I've a message object that is serialized to a xml string and communicating
between a client and server with a connection-oriented (TCP) socket. Unlike
a UDP, in a TCP socket, the 'Receive' function will try to read in as much
data as possible from the buffer and return, and therefore, sometimes the
message isn't complete with just one 'Receive' call.

In order to make sure that my message is complete, I've added in a 'STX' and
'EOT' into my xml string just to make sure that whether if more than 1
'Receive' call is needed to complete the message. It definitely works, but
I'm just wondering if there is any other smarter way of doing it? Is it
possible do it like the UDP's 'receivefrom' function where it will only
return when the whole datagram is received? I'm using VS2005 now, any new
tricks?

Thanks,
Simon

Author
26 Jan 2006 5:48 AM
Cor Ligthert [MVP]
Simon,

The smartest way is probably using a webservice that collects your data.

(What is very easy to make using VB.Net 2005)

Just my thought,

Cor
Author
26 Jan 2006 6:34 AM
Simon Says
It sounds good if mine is a web application. However, my is a Windows
application. Will it still works?
--Simon

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23SMLGwjIGHA.984@tk2msftngp13.phx.gbl...
> Simon,
>
> The smartest way is probably using a webservice that collects your data.
>
> (What is very easy to make using VB.Net 2005)
>
> Just my thought,
>
> Cor
>
Author
26 Jan 2006 7:12 AM
Cor Ligthert [MVP]
Author
27 Jan 2006 3:35 AM
Simon Says
thank .

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23ZLCHfkIGHA.3120@TK2MSFTNGP10.phx.gbl...
> Simon,
>
> Have a look at this sample to get some ideas.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vbwlkCreatingDistributedWebApplicationWalkthrough.asp
>
> I hope this helps,
>
> Cor
>
>
Author
26 Jan 2006 2:15 PM
Carlos J. Quintero [VB MVP]
Hi Simon,

There are three common approaches to know when a message is complete:

- Use a delimiter (your approach)
- Use a message header (2 bytes, for example) to inform about of the length
of the message.
- Use fixed-length messages

With either approach you will need to loop in the receiving code until the
message is complete, because there are several buffers involved.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


Show quoteHide quote
"Simon Says" <win_for_s***@hotmail.com> escribió en el mensaje
news:%23EHdySjIGHA.2300@TK2MSFTNGP15.phx.gbl...
> Hi all,
>
> I've a message object that is serialized to a xml string and communicating
> between a client and server with a connection-oriented (TCP) socket.
> Unlike a UDP, in a TCP socket, the 'Receive' function will try to read in
> as much data as possible from the buffer and return, and therefore,
> sometimes the message isn't complete with just one 'Receive' call.
>
> In order to make sure that my message is complete, I've added in a 'STX'
> and 'EOT' into my xml string just to make sure that whether if more than 1
> 'Receive' call is needed to complete the message. It definitely works, but
> I'm just wondering if there is any other smarter way of doing it? Is it
> possible do it like the UDP's 'receivefrom' function where it will only
> return when the whole datagram is received? I'm using VS2005 now, any new
> tricks?
>
> Thanks,
> Simon
>
Author
27 Jan 2006 3:41 AM
Simon Says
But with XML data, is there any more efficient way of doing it? I'm looking
at some of the XML functions right now, and am exploring the
'CanDeserialize' function in the XML.Serialization namespace. Thinking of
putting all received message from the socket into a stream, and keep
checking if 'CanDeserialize' return true. If the message is not complete,
then 'CanDeserialize' will return false on the stream.

Any pointers?


Show quoteHide quote
"Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in message
news:%23IXsuLoIGHA.3408@TK2MSFTNGP12.phx.gbl...
> Hi Simon,
>
> There are three common approaches to know when a message is complete:
>
> - Use a delimiter (your approach)
> - Use a message header (2 bytes, for example) to inform about of the
> length of the message.
> - Use fixed-length messages
>
> With either approach you will need to loop in the receiving code until the
> message is complete, because there are several buffers involved.
>
> --
>
> Best regards,
>
> Carlos J. Quintero
>
> MZ-Tools: Productivity add-ins for Visual Studio
> You can code, design and document much faster:
> http://www.mztools.com
>
>
> "Simon Says" <win_for_s***@hotmail.com> escribió en el mensaje
> news:%23EHdySjIGHA.2300@TK2MSFTNGP15.phx.gbl...
>> Hi all,
>>
>> I've a message object that is serialized to a xml string and
>> communicating between a client and server with a connection-oriented
>> (TCP) socket. Unlike a UDP, in a TCP socket, the 'Receive' function will
>> try to read in as much data as possible from the buffer and return, and
>> therefore, sometimes the message isn't complete with just one 'Receive'
>> call.
>>
>> In order to make sure that my message is complete, I've added in a 'STX'
>> and 'EOT' into my xml string just to make sure that whether if more than
>> 1 'Receive' call is needed to complete the message. It definitely works,
>> but I'm just wondering if there is any other smarter way of doing it? Is
>> it possible do it like the UDP's 'receivefrom' function where it will
>> only return when the whole datagram is received? I'm using VS2005 now,
>> any new tricks?
>>
>> Thanks,
>> Simon
>>
>
>