I have an application that, from time to time needs to send an xml file from one terminal to another.
As you know, XML files can be fairly long, and therefore often I exceed the maximum length that can be transmitted in one go.
However, I have no ide how to go about breaking down the data, ensuring it arrives complete at the other end, and rebuilding it.
Can anybody help me on this?
The code I currently have is as Follows;
(To Send the data)
And to Receive:
As you know, XML files can be fairly long, and therefore often I exceed the maximum length that can be transmitted in one go.
However, I have no ide how to go about breaking down the data, ensuring it arrives complete at the other end, and rebuilding it.
Can anybody help me on this?
The code I currently have is as Follows;
(To Send the data)
VB.NET:
Dim returndata As String = ""
Dim tcpClient As New System.Net.Sockets.TcpClient()
Try
tcpClient.Connect(IP, Port)
Catch ex As Exception
Return "ERROR"
End Try
Dim networkStream As Net.Sockets.NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Debug.WriteLine(("Sent: " & Query & vbCrLf))
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Query)
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host
returndata = System.Text.Encoding.ASCII.GetString(bytes)
Debug.WriteLine("Host returned: " & returndata.ToString & vbCrLf)
Else
If Not networkStream.CanRead Then
Debug.WriteLine("cannot write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Debug.WriteLine("cannot read data from this stream")
tcpClient.Close()
End If
End If
End If
And to Receive:
VB.NET:
Dim tcpClient As TcpClient = TCPL.AcceptTcpClient()
Debug.WriteLine("Connection accepted.")
' Get the stream
Dim networkStream As NetworkStream = tcpClient.GetStream()
' Read the stream into a byte array
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Return the data received from the client
Dim clientdata As String = System.Text.Encoding.ASCII.GetString(bytes)
Debug.WriteLine(("Client sent: " + clientdata))
Dim Query As String = clientdata
Dim Reply As String = ""
Debug.WriteLine("Received Query: " & Query)