Solved

NetworkStream not including the last quotation?

Posted on 2009-07-09
3
198 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now