Home > OS >  vb.net stream_writer encoding
vb.net stream_writer encoding

Time:11-02

Please to tell me how to convert a string message to ascii chars to send it over the stream writer, I have been struggling for hours/days , the client controller is receiving System.Byte[] . I think I am not correctly sending ascii char sequence.

   Public Sub sub_send(ByVal str_my_msg As String)

        Dim string_converted_to_ascii_chars As [Byte]() = Encoding.ASCII.GetBytes(str_my_msg )

        stream_writer = New StreamWriter(my_client.GetStream)

        stream_writer.Write(string_converted_to_ascii_chars )

        stream_writer.Flush()

       
    End Sub

CodePudding user response:

Try this:

Public Sub sub_send(ByVal str_my_msg As String)
    Dim string_converted_to_ascii_chars As [Char]() = str_my_msg.ToCharArray()

    stream_writer = New StreamWriter(my_client.GetStream)
    stream_writer.Write(string_converted_to_ascii_chars)
    stream_writer.Flush()
End Sub
  • Related