shafaatmosvi
New member
- Joined
- Nov 6, 2012
- Messages
- 2
- Programming Experience
- 3-5
Server Code:
Client Code:
The client works fine, but the server has some read issues with the network stream. It gets stuck with this line "networkStream1.Read(bytes, 0, CInt(client.ReceiveBufferSize))" and never gets the data that client sends it and in vain keeps waiting for it. What is the problem here? Please, help. Thanks.
Imports System Imports System.Net.Sockets Imports System.Net Imports System.Text Imports Microsoft.VisualBasic Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1") Dim server As New TcpListener(localAddr, 55556) server.Start() Dim client As TcpClient = server.AcceptTcpClient() Dim networkStream1 As NetworkStream = client.GetStream() Dim bytes(client.ReceiveBufferSize) As Byte Dim dataReceived As String While True networkStream1.Read(bytes, 0, CInt(client.ReceiveBufferSize)) dataReceived = Encoding.ASCII.GetString(bytes) End While End Sub End Class
Client Code:
Imports System Imports System.Net.Sockets Imports System.Net Imports System.Text Imports Microsoft.VisualBasic Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim tcpClient1 As New System.Net.Sockets.TcpClient() tcpClient1.Connect("127.0.0.1", 55556) Dim networkStream2 As NetworkStream = tcpClient1.GetStream() Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("hello!") TextBox1.Text = sendBytes(0) networkStream2.Write(sendBytes, 0, sendBytes.Length) End Sub End Class
The client works fine, but the server has some read issues with the network stream. It gets stuck with this line "networkStream1.Read(bytes, 0, CInt(client.ReceiveBufferSize))" and never gets the data that client sends it and in vain keeps waiting for it. What is the problem here? Please, help. Thanks.
Last edited by a moderator: