Solved

NetworkStream not including the last quotation?

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

747 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

12 Experts available now in Live!

Get 1:1 Help Now