PC Review


Reply
Thread Tools Rate Thread

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

 
 
Simon Says
Guest
Posts: n/a
 
      26th Jan 2006
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


 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      26th Jan 2006
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


 
Reply With Quote
 
 
 
 
Simon Says
Guest
Posts: n/a
 
      26th Jan 2006
It sounds good if mine is a web application. However, my is a Windows
application. Will it still works?
--Simon

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      26th Jan 2006
Simon,

Have a look at this sample to get some ideas.

http://msdn.microsoft.com/library/de...alkthrough.asp

I hope this helps,

Cor


 
Reply With Quote
 
Carlos J. Quintero [VB MVP]
Guest
Posts: n/a
 
      26th Jan 2006
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" <(E-Mail Removed)> escribió en el mensaje
news:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Simon Says
Guest
Posts: n/a
 
      27th Jan 2006
thank .

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Simon,
>
> Have a look at this sample to get some ideas.
>
> http://msdn.microsoft.com/library/de...alkthrough.asp
>
> I hope this helps,
>
> Cor
>
>



 
Reply With Quote
 
Simon Says
Guest
Posts: n/a
 
      27th Jan 2006
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?


"Carlos J. Quintero [VB MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> escribió en el mensaje
> news:%(E-Mail Removed)...
>> 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
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows 7: best firewall and best antivirus and best anti-spamsoftware is/are? RayLopez99 DIY PC 21 3rd Sep 2010 03:27 PM
what is the best way to resize test that "best fits" the text box utahjohn Microsoft Word Document Management 2 7th Dec 2009 09:15 AM
Best seller,Best service,Provide Best bot cherrytree Windows Vista Games 0 29th Oct 2007 03:33 AM
What is the best way to make dual-way xml databinding? Stan Microsoft ASP .NET 3 5th May 2005 03:07 PM
Best way to synchronise data between databases - best approach? Angus Comber Microsoft Access 0 1st Jan 2004 01:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:47 AM.