Solved

NetworkStream not including the last quotation?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

776 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