Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a multithreading messenger using vb.net

The idea is simple. sending a XML data through client server. I use thread to sending ping from server to client. but, the XMLs are colide. So the client or server can't read it, causing XML exception : "There are multiple root elements. Line 13, position 20."

how can i fix it?


Thanks,

Dwi Prawira

note: i use dataset.writexml() to stream and dataset.readxml() when sending and receiving data

here is my code for sending and receiving data..
VB
Public Sub SendRequest(ByVal data As clsXMLData, ByVal cl As TcpClient)

     Dim xmlDoc As New Xml.XmlDocument()

     Dim dt As New DataTable("SendResponse")
     dt.Columns.Add("Action")
     dt.Columns.Add("Value1")
     dt.Columns.Add("Value2")
     dt.Columns.Add("Value3")
     dt.Columns.Add("Value4")
     dt.Columns.Add("Value5")
     dt.Columns.Add("Value6")
     dt.Columns.Add("Value7")
     dt.Columns.Add("Value8")

     dt.Rows.Add(data.Action, data.Value1, data.Value2, data.Value3, data.Value4, _
                 data.Value5, data.Value6, data.Value7, data.Value8)
     Dim strm As NetworkStream = cl.GetStream
          
     dt.WriteXml(strm)
     strm.Flush()
 End Sub

 Public Function ReceiveResponse(ByVal strm As NetworkStream, _
                            ByVal cl As TcpClient) As clsXMLData
     Dim ds As New DataSet("ReceiveResponse")

     ds.ReadXml(NetToMemStream(strm, cl))
     Dim data As New clsXMLData
     With data
         .Action = ds.Tables(0).Rows.Item(0).Item(0)
         .Value1 = ds.Tables(0).Rows.Item(0).Item(1)
         .Value2 = ds.Tables(0).Rows.Item(0).Item(2)
         .Value3 = ds.Tables(0).Rows.Item(0).Item(3)
         .Value4 = ds.Tables(0).Rows.Item(0).Item(4)
         .Value5 = ds.Tables(0).Rows.Item(0).Item(5)
         .Value6 = ds.Tables(0).Rows.Item(0).Item(6)
         .Value7 = ds.Tables(0).Rows.Item(0).Item(7)
         .Value8 = ds.Tables(0).Rows.Item(0).Item(8)
     End With
     Return data

 End Function
Posted
Updated 3-Aug-10 17:49pm
v4

By only dealing with one XML file at a time ?
 
Share this answer
 
Comments
Dwi Prawira 2-Aug-10 3:32am    
i know that.. but in multithreading sometimes a thread with the other thread writexml together.. can i make some queue when doing writexml??
Simon_Whale 3-Aug-10 11:20am    
Reason for my vote of 5
the simple answers are always the best
sounds like you are allowing the threads to use the same xml document or file.

but that is a guess as your narrative is sparse and lacks any code snippets relevant to your question
 
Share this answer
 
v2
Comments
Dwi Prawira 3-Aug-10 23:48pm    
the XML write to the network stream, not to a file.. i has updated my question with code snippets.. thanks..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900