Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:49:44+00:00 2026-06-08T20:49:44+00:00

My application is receiving commands via TCP, if I attempt to compare the command

  • 0

My application is receiving commands via TCP, if I attempt to compare the command the comparison always fails.

The message is converted to a byte() and back but should compare ok in the below example? Or am I missing something?

Imports MyApp.Client

Public Class Form1
    Public Delegate Sub MessageReceivedHandler(ByVal message As String)

    Private Sub Message_Received(ByVal message As String)
        'update the display using invoke
        Invoke(New MessageReceivedHandler(AddressOf PrintToScreen), New Object() {message})
    End Sub

    Private Sub PrintToScreen(ByVal msg As String)
        Select Case msg
            Case "#all"
                'Do Something
            Case Else
                'Do Something Else
        End Select
    End Sub
End Class


'Client class
Public Class Client
    Private _tcpClient As TcpClient
    Public Event MessageReceived As MessageReceivedHandler

    Public Sub Connect(ByVal address As IPAddress, ByVal port As Integer)
        _tcpClient = New TcpClient()
        Dim serverEndPoint As New IPEndPoint(address, port)
        _tcpClient.Connect(serverEndPoint)
        ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Read))
    End Sub

    Public Sub Send(ByVal buffer As Byte())
        _tcpClient.GetStream().Write(buffer, 0, buffer.Length)
        _tcpClient.GetStream().Flush()
    End Sub

    Private Sub Read()
        Dim encoder As New ASCIIEncoding()
        Dim buffer As Byte() = New Byte(4095) {}
        Dim bytesRead As Integer
        While True
            Try
                bytesRead = _tcpClient.GetStream().Read(buffer, 0, 4096)
                RaiseEvent MessageReceived(encoder.GetString(buffer, 0, bytesRead).ToString)
            Catch ex As IO.IOException
                Application.Exit()
            End Try
        End While
    End Sub

    Public Sub Dispose()
        _tcpClient.Close()
    End Sub
End Class

The variable is a string containing the same text as the case, yet it fails the comparison:

Msg Variable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:49:45+00:00Added an answer on June 8, 2026 at 8:49 pm

    Found the problem, the sending application was adding a vbNullChar to the end of the string before converting to a byte() and sending over. (Could not see a method to remove it from the string converted on the receiving end)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TCP server application in which on receiving an incoming connection, I
I have a server application receiving messages from a JMS queue. And client applications
i want to start an application on receiving sms from a particular number. i
I have an application which is receiving data for thousands (say 50,000) subjects. Each
i have an application in which i am receiving WALLPAPER_CHANGED broadcast. the problem is
I'm receiving suddenly this error on a Win2003 Server Web Application: Microsoft VBScript runtime
I'm receiving a rather cryptic error when attempting to debug a simple C++ application.
I am using the APNS for receiving push notifications in my application. The problem
I have an application that will mail users attachments of text files. Receiving users
I would like to implement an application for block a mobile number for receiving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.