I am writing two programs that are part of a Bulletin board system.
The program works right, but when information is downloaded, the server
program refuses to send more than 9 Kilobytes of data to the client.
How can this be fixed?
The code is:
Server (Running in a separate thread from UI):
H:
Const portNumber As Integer = 8000
Dim tcpListener As New TcpListener(por tNumber)
tcpListener.Sta rt()
Try
Dim tcpClient As TcpClient = tcpListener.Acc eptTcpClient()
Dim networkStream As NetworkStream = tcpClient.GetSt ream()
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
networkStream.R ead(bytes, 0,
CInt(tcpClient. ReceiveBufferSi ze))
Dim clientdata As String = Encoding.Unicod e.GetString(byt es)
Dim responseString As String = TextBox1.Text
Dim sendBytes As [Byte]() = Encoding.Unicod e.GetBytes(resp onseString)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)
tcpClient.Close ()
tcpListener.Sto p()
Catch e As Exception
End Try
GoTo H
End Sub
Try
Dim tcpClient As New System.Net.Sock ets.TcpClient()
tcpClient.Conne ct(ip, port)
Dim networkStream As NetworkStream = tcpClient.GetSt ream()
If networkStream.C anWrite And networkStream.C anRead Then
Dim sendBytes As [Byte]() = Encoding.Unicod e.GetBytes(Text Box2.Text)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
networkStream.R ead(bytes, 0,
CInt(tcpClient. ReceiveBufferSi ze))
Dim returndata As String = Encoding.Unicod e.GetString(byt es)
Me.Close()
Else
If Not networkStream.C anRead Then
MsgBox("Data cannot be written.")
tcpClient.Close ()
Else
If Not networkStream.C anWrite Then
MsgBox("Data cannot be read.")
tcpClient.Close ()
End If
End If
End If
Catch ex As Exception
MsgBox("Error! Sever is not functioning!")
MsgBox(ex.ToStr ing)
MsgBox(ex.Messa ge)
End Try
Sorry about the sloppy coding. This is partially based on something i
found on Egghead cafe. If it matters, I am using a fast computer with
Windows XP Professional.
The program works right, but when information is downloaded, the server
program refuses to send more than 9 Kilobytes of data to the client.
How can this be fixed?
The code is:
Server (Running in a separate thread from UI):
H:
Const portNumber As Integer = 8000
Dim tcpListener As New TcpListener(por tNumber)
tcpListener.Sta rt()
Try
Dim tcpClient As TcpClient = tcpListener.Acc eptTcpClient()
Dim networkStream As NetworkStream = tcpClient.GetSt ream()
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
networkStream.R ead(bytes, 0,
CInt(tcpClient. ReceiveBufferSi ze))
Dim clientdata As String = Encoding.Unicod e.GetString(byt es)
Dim responseString As String = TextBox1.Text
Dim sendBytes As [Byte]() = Encoding.Unicod e.GetBytes(resp onseString)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)
tcpClient.Close ()
tcpListener.Sto p()
Catch e As Exception
End Try
GoTo H
End Sub
Try
Dim tcpClient As New System.Net.Sock ets.TcpClient()
tcpClient.Conne ct(ip, port)
Dim networkStream As NetworkStream = tcpClient.GetSt ream()
If networkStream.C anWrite And networkStream.C anRead Then
Dim sendBytes As [Byte]() = Encoding.Unicod e.GetBytes(Text Box2.Text)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
networkStream.R ead(bytes, 0,
CInt(tcpClient. ReceiveBufferSi ze))
Dim returndata As String = Encoding.Unicod e.GetString(byt es)
Me.Close()
Else
If Not networkStream.C anRead Then
MsgBox("Data cannot be written.")
tcpClient.Close ()
Else
If Not networkStream.C anWrite Then
MsgBox("Data cannot be read.")
tcpClient.Close ()
End If
End If
End If
Catch ex As Exception
MsgBox("Error! Sever is not functioning!")
MsgBox(ex.ToStr ing)
MsgBox(ex.Messa ge)
End Try
Sorry about the sloppy coding. This is partially based on something i
found on Egghead cafe. If it matters, I am using a fast computer with
Windows XP Professional.
Comment