Hi, I have a problem with sending a file.
I have a client application that connects to a server and sends the
string "data". Then it sends a file. If the server receives "data",
the method getCsv() is started (this receives the file)
The file however isn't received completely (most of the time)
this is my servercode:
Imports System.Net.Sock ets
Imports System.Text
Imports System.Xml
Imports System.IO
Class server
Shared Sub readStream(ByVa l tcpCl As TcpClient, ByVal netwstr
As NetworkStream)
Dim clientdata As String
Dim bytes(tcpCl.Rec eiveBufferSize) As Byte
Do
clientdata = ""
If (netwstr.DataAv ailable) Then
netwstr.Read(by tes, 0,
CInt(tcpCl.Rece iveBufferSize))
clientdata = Encoding.ASCII. GetString(bytes )
End If
If (clientdata.Com pareTo("data") =
0) Then
Exit Sub
End If
Loop Until False
End Sub
Shared Sub getCsv(ByVal tcpCl As TcpClient, ByVal netwstr As
NetworkStream)
Dim bytes2(tcpCl.Re ceiveBufferSize ) As Byte
Dim myCompleteMessa ge As String
Dim numberOfBytesRe ad As Integer
Do
numberOfBytesRe ad = netwstr.Read(by tes2, 0,
bytes2.Length)
myCompleteMessa ge =
[String].Concat(myCompl eteMessage,
Encoding.ASCII. GetString(bytes 2, 0, numberOfBytesRe ad))
Loop While netwstr.DataAva ilable
Dim fi As New FileInfo("Test. csv")
Dim sw As StreamWriter = fi.CreateText()
sw.Write(myComp leteMessage)
sw.Close()
Console.WriteLi ne("Data received")
End Sub
Shared Sub Main()
Const portNumber As Integer = 1234
Dim tcpListener As New TcpListener(por tNumber)
Dim tcpClient As TcpClient
tcpListener.Sta rt()
Console.WriteLi ne("Listening.. .")
Try
tcpClient = tcpListener.Acc eptTcpClient()
Console.WriteLi ne("Connection
accepted.")
Dim networkStream As NetworkStream =
tcpClient.GetSt ream()
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
Do
readStream(tcpC lient, networkStream)
getCsv(tcpClien t, networkStream)
Loop Until False
Catch e As Exception
Console.WriteLi ne(e.ToString() )
Console.ReadLin e()
End Try
End Sub
End Class
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---