send file

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?
 
M

Mike Bulava

User FileStream.Read to get the byte array to send rather then converting
twice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

NNTP Client 4
TCP Transfer issues 3
Data Logger 1
Testing client server application from single computer 3
How to debug this? 10
HELP Please!!!! 3
Write Data To File 15
trouble reading word documents 16

Top