HighTechTalks DotNet Forums  

Re: simple question about socket communication

Dotnet Distributed Applications microsoft.public.dotnet.distributed_apps


Discuss Re: simple question about socket communication in the Dotnet Distributed Applications forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ivar Lumi
 
Posts: n/a

Default Re: simple question about socket communication - 01-18-2007 , 09:38 AM







Hi,

What about implementing commnd like:

clinet: LoadXml size_of_data_to_be_sent<CRLF>
server: OK send data<CRLF>
client: sends data
server reads size_of_data_to_be_sent
server: OK<CRLF>

this ensures that all data is sent, and you see result always.

"Ben" <Ben (AT) discussions (DOT) microsoft.com> wrote

Quote:
i'm trying to send some xml data over a socket, and then receive a reply
from
the server.
I've been doing it like this:

'client:
dim xmldoc as new XmlDocument
'...(make the xml up)
dim t as New TcpClient()
t.Connect(host,port) 'connects ok...
dim thestream as NetworkStream = t.GetStream()
xmldoc.Save(thestream)
dim responsedoc as new XmlDocument()
'the next bit is where it gets stuck...
responsedoc.Load(thestream)

'server:
dim thelistener as new TcpListener(IPAddress.Loopback, port)
thelistener.Start()
dim theclient as TcpClient = thelistener.AcceptTcpClient()
dim thestream as NetworkStream = theclient.GetStream()
dim recdxmldoc as new XmlDocument()
recdxmldoc.Load(thestream) 'only completes if the client disconnects...?

now this all works fine if the client disconnects as soon as it has sent
the
document, i.e. if it closes the stream and client instead of the bit
following where i've put 'the next bit is where it gets stuck'.
But my problem is that if the client tries to receive data back from the
socket, then the client blocks on responsedoc.Load, and the server blocks
on
recdxmldoc.Load.
I think what I need is some way of the client saying "over" but not "over
and out".

How do I do this please? I tried doing thestream.Close() on the client,
but
then when I tried to read from it, it throws an exception telling me I
cannot
perform this action on a disposed object. I've also not changed the client
from its default of 'doesn't own socket'. I presume that's right?
Cheers for any help




Reply With Quote
  #2  
Old   
Ivar Lumi
 
Posts: n/a

Default Re: simple question about socket communication - 01-18-2007 , 10:02 AM







First you read data to MemoryStream , then from memory stream you load xml.

You send same way, first write xml to memorystream, so you know size then,
......

"Ben" <Ben (AT) discussions (DOT) microsoft.com> wrote

Quote:
I don't understand what you mean. LoadXml takes an xml string as a
parameter,
so how can I pass the size of the data to be sent?


"Ivar Lumi" wrote:


Hi,

What about implementing commnd like:

clinet: LoadXml size_of_data_to_be_sent<CRLF
server: OK send data<CRLF
client: sends data
server reads size_of_data_to_be_sent
server: OK<CRLF

this ensures that all data is sent, and you see result always.

"Ben" <Ben (AT) discussions (DOT) microsoft.com> wrote in message
news:17B05A64-7009-4A67-AA1E-2B388DCA2275 (AT) microsoft (DOT) com...
i'm trying to send some xml data over a socket, and then receive a
reply
from
the server.
I've been doing it like this:

'client:
dim xmldoc as new XmlDocument
'...(make the xml up)
dim t as New TcpClient()
t.Connect(host,port) 'connects ok...
dim thestream as NetworkStream = t.GetStream()
xmldoc.Save(thestream)
dim responsedoc as new XmlDocument()
'the next bit is where it gets stuck...
responsedoc.Load(thestream)

'server:
dim thelistener as new TcpListener(IPAddress.Loopback, port)
thelistener.Start()
dim theclient as TcpClient = thelistener.AcceptTcpClient()
dim thestream as NetworkStream = theclient.GetStream()
dim recdxmldoc as new XmlDocument()
recdxmldoc.Load(thestream) 'only completes if the client
disconnects...?

now this all works fine if the client disconnects as soon as it has
sent
the
document, i.e. if it closes the stream and client instead of the bit
following where i've put 'the next bit is where it gets stuck'.
But my problem is that if the client tries to receive data back from
the
socket, then the client blocks on responsedoc.Load, and the server
blocks
on
recdxmldoc.Load.
I think what I need is some way of the client saying "over" but not
"over
and out".

How do I do this please? I tried doing thestream.Close() on the client,
but
then when I tried to read from it, it throws an exception telling me I
cannot
perform this action on a disposed object. I've also not changed the
client
from its default of 'doesn't own socket'. I presume that's right?
Cheers for any help







Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.