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..
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