Solved

NetworkStream not including the last quotation?

Posted on 2009-07-09
3
205 Views
Last Modified: 2012-05-07
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
Comment
Question by:freebullets
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Expert Comment

by:graye
ID: 24841075
add a line after your Write() method
NetworkStream.Close()
0
 
LVL 1

Author Comment

by:freebullets
ID: 24846497
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
 
LVL 1

Accepted Solution

by:
freebullets earned 0 total points
ID: 25002067
I fixed it by using StreamReader/Writer instead.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question