H
Henk
Hi, I made a client and server application. I'm trying to send an xml
file from the server to the client. It works, but there are some
problems: the file the client receives is the same as the file the
server sends but there are some spaces added at the end, and this
causes that I can't open the file correctly.
This is part of my server code:
Dim fs As FileStream
fs = New FileStream("Employees.xml",
FileMode.Open)
Dim objReader As New StreamReader(fs)
Dim responseString As String
responseString = objReader.ReadToEnd
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0,
sendBytes.Length)
objReader.Close()
fs.Close()
Console.WriteLine("Message sent")
This is a part of my client code:
[code:1:4eac204a01]
Try
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))
Dim returndata As String =
Encoding.ASCII.GetString(bytes)
Dim fs As FileStream
fs = New FileStream("Employees.xml",
FileMode.Create)
Dim objWriter As New StreamWriter(fs)
objWriter.Write(returndata)
objWriter.Close()
fs.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
[/code:1:4eac204a01]
Can somebody tell me what I am doing wrong or give me another way to
send the file?
file from the server to the client. It works, but there are some
problems: the file the client receives is the same as the file the
server sends but there are some spaces added at the end, and this
causes that I can't open the file correctly.
This is part of my server code:
Dim fs As FileStream
fs = New FileStream("Employees.xml",
FileMode.Open)
Dim objReader As New StreamReader(fs)
Dim responseString As String
responseString = objReader.ReadToEnd
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0,
sendBytes.Length)
objReader.Close()
fs.Close()
Console.WriteLine("Message sent")
This is a part of my client code:
[code:1:4eac204a01]
Try
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))
Dim returndata As String =
Encoding.ASCII.GetString(bytes)
Dim fs As FileStream
fs = New FileStream("Employees.xml",
FileMode.Create)
Dim objWriter As New StreamWriter(fs)
objWriter.Write(returndata)
objWriter.Close()
fs.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
[/code:1:4eac204a01]
Can somebody tell me what I am doing wrong or give me another way to
send the file?