XMLDocument and network stream

anthony.selby

Well-known member
Joined
Sep 3, 2009
Messages
65
Programming Experience
5-10
I'm trying to send a XML serialized class over a network stream

the send is working

VB.NET:
        Dim IP As Net.IPAddress = System.Net.IPAddress.Parse(IPAddress)
        Dim IPE As New Net.IPEndPoint(IP, 10003)
        Dim TCPClient As New Net.Sockets.TcpClient
        Dim MS As New IO.MemoryStream
        Dim IPn As System.Net.Sockets.NetworkStream

            TCPClient.Connect(IPE)

            IPn = TCPClient.GetStream

            TCPXS.Serialize(MS, Message)

            MS.Position = 0

            Dim XMLDocument As New Xml.XmlDocument()

            XMLDocument.Load(MS)

            XMLDocument.Save(IPn)

            IPn.Flush()

When I recieve it I and convert it back to a object with this

VB.NET:
  TCPListen.Start()
            Dim TClient As Net.Sockets.TcpClient
            Dim TStream As Net.Sockets.NetworkStream

            TClient = TCPListen.AcceptTcpClient
            TStream = TClient.GetStream

            'Dim XmlReader As New Xml.XmlTextReader(TStream)

            Dim XMLFile As New Xml.XmlDocument

            Try
                XMLFile.Load(TStream)
            Catch exp As Exception
'ERROR HERE
            End Try

            XMLFile.Save(MS)

            MS.Position = 0


            TempSendPatientStructure = CType(TCPXS.Deserialize(MS), SendPatientStructure)

I always get an error {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."} The XMLFile has the xml document in it most of the time and I can go on and everything works but 1 out of every 5 times it doesn't work at all and the XMLFile contains nothing ... does anyone know whats going on ? I've googled for a while I don't see anything that will help.

Thanks
 
I load my data into a dataset, which work fine over a network, i can save, edit, delete, search and do reports, and all the data is on a remote pc but now I want to do this over the internet ... I can connect to the sever by using a socket and that part work fine.... but when I want to read the data in to my Dataset, I get problem on problem....

any ideas ... :(
 
Now this source at the bottom work perfect over a local network, my problem is to let the same code work between a sever and a client socket....

I do have a static IP address and I tested the server and client, which work also... now how do i let this work ....



Public ds_Employee As DataSet = New DataSet()

Dim a As Integer 'the index of the record we are seeing
Dim count_Employees As Integer 'the number of records

Sub sFill()
txtShortKey.Text = ds_Employee.Tables(0).Rows(a).Item("sKey")
txtName.Text = ds_Employee.Tables(0).Rows(a).Item("Name")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds_Employee.ReadXml("C:\ds_Employees.xml", XmlReadMode.Auto)
'counts the records
count_Employees = ds_Employee.Tables(0).Rows.Count
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
' Update the database with the changes made to the local resident DataSet.
Dim newRow As DataRow
newRow = ds_Employee.Tables(0).NewRow()

newRow("sKey") = txtShortKey.Text
newRow("Date") = txtName.Text

ds_Employee.Tables(0).Rows.Add(newRow)
ds_Employee.WriteXml("C:\ds_Employee.xml", XmlWriteMode.IgnoreSchema)

count_Employees = count_Employees + 1
a = 0

MessageBox.Show("The Employee is successfully updated.", _
"Update", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Catch ex As Exception
MsgBox("Error with the databindings: " + ex.Message)
End Try
End Sub

Private Sub btnSaveEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveEdit.Click
'save edit
ds_Employee.Tables(0).Rows(a).Item("sKey") = txtShortKey.Text
ds_Employee.Tables(0).Rows(a).Item("Name") = txtName.Text

ds_Employee.WriteXml("C:\ds_Employees.xml", XmlWriteMode.IgnoreSchema)

MessageBox.Show("The Employee Details is successfully updated.", _
"Update", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
'delete
If MessageBox.Show("Are you sure you want to delete this from the database?", "Deleteing", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
= Windows.Forms.DialogResult.Yes Then
'update employee
Try
ds_Employee.Tables(0).Rows(a).Delete()
count_Employees = count_Employees - 1
a = 0
ds_Employee.WriteXml("C:\ds_Employees.xml", XmlWriteMode.IgnoreSchema)
Catch ex As Exception
MsgBox("Error with the databindings: " + ex.Message)
End Try
End If
End Sub

Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
For b = 0 To count_Employees - 1
If ds_Employee.Tables(0).Rows(b).Item("sKey").ToString.ToUpper Like ((txtShortKey.Text.ToUpper) & "*") Then
a = b
sFill()
Exit For
End If
Next
End Sub
 
Back
Top