Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Select case and ASCII encoding

$
0
0
Hi,

I am playing around with system.net.sockets and have a problem. I am converting an ASCII message to a string, but when testing the string with a select case it is not recognised. I am not sure what to do. When I debug and step into "Select Case mymessage" the variable contains the word "test". However, the case statement is ignored.

Could somebody explain why, and how to fix?

FIA



    Private Sub HandleClientComm(ByVal client As Object)

        Dim tcpClient As TcpClient = DirectCast(client, TcpClient)
        Dim clientStream As NetworkStream = tcpClient.GetStream()

        Dim message As Byte() = New Byte(4095) {}
        Dim bytesRead As Integer

        While True
            bytesRead = 0
            bytesRead = clientStream.Read(message, 0, 4096)  'blocks until a client sends a message
            'MsgBox(message)
            If bytesRead = 0 Then
                Exit While    'the client has disconnected from the server
            End If


            'message has successfully been received
            'Dim encoder As New ASCIIEncoding()
            Dim serverResponse As String = "I have received your message"
            Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(serverResponse)
            clientStream.Write(sendBytes, 0, sendBytes.Length)


            Dim mymessage = Encoding.ASCII.GetString(message)
            

            Select Case mymessage
                Case "test"
                    LeaveDomain()
                Case "test1"
                    JoinDomain()
            End Select


        End While

        tcpClient.Close()
    
    End Sub





Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>