469,964 Members | 1,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

send file

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?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #1
1 1927
User FileStream.Read to get the byte array to send rather then converting
twice
"Henk" <kl*******@hotmail-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
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?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fatih BOY | last post: by
reply views Thread by zhimin | last post: by
4 posts views Thread by ad | last post: by
9 posts views Thread by eswanson | last post: by
3 posts views Thread by =?Utf-8?B?SHVnaA==?= | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.