Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

NetworkStream not including the last quotation?

I'm trying to make a simple chat client.  But it seems that the "Dim ClientData As String = Encoding.ASCII.GetString(RevievedBytes)" is returning a string without the trailing quotation.  During a step-into, ClientData was "something.  If I manually put the other quotation on the end during a step-into, it would work.  Why is this happening?  Full project available at http://www.mediafire.com/?lhaymkulizn
Private Sub Listen(ByVal Server As String, ByVal PortNum As Int16)
    Dim MyTCPListener As New TcpListener(System.Net.IPAddress.Parse(Server), PortNum)
    MyTCPListener.Start()
    Try
      Dim MyTCPClient As TcpClient = MyTCPListener.AcceptTcpClient()
      Dim NetworkStream As NetworkStream = MyTCPClient.GetStream()
      Dim RevievedBytes(MyTCPClient.ReceiveBufferSize) As Byte
      NetworkStream.Read(RevievedBytes, 0, CInt(MyTCPClient.ReceiveBufferSize))
 
      Dim ClientData As String = Encoding.ASCII.GetString(RevievedBytes)
      'Dim data2 As String = ClientData & Chr(34)
      Dim ClientParameters() As String = ClientData.Split("~")
      Dim ResponseString As String = ""
 
      Status = ClientData
      Select Case ClientParameters(0)
        Case "/send"
          ResponseString = "/print~" & ClientParameters(1)
        Case "/connect"
          'ConnectedClients.Add(System.Net.IPAddress.Parse(ClientParameters(1)))
          ResponseString = "/ok"
      End Select
 
      Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(ResponseString)
      NetworkStream.Write(sendBytes, 0, sendBytes.Length)
      MyTCPClient.Close()
      MyTCPListener.Stop()
    Catch ex As Exception
      MessageBox.Show(ex.Message)
    End Try
  End Sub

Open in new window

0
freebullets
Asked:
freebullets
  • 2
1 Solution
 
grayeCommented:
add a line after your Write() method
NetworkStream.Close()
0
 
freebulletsAuthor Commented:
The problem is visible at this line.  When stepping into, the value of it is "clientdatahere.  It should be "clientdatahere".
Dim ClientData As String = Encoding.ASCII.GetString(RevievedBytes)

Open in new window

0
 
freebulletsAuthor Commented:
I fixed it by using StreamReader/Writer instead.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now