vb.net stream_writer 编码

vb.net stream_writer encoding

请告诉我如何将字符串消息转换为 ascii 字符以通过流编写器发送它,我一直在努力 hours/days ,客户端控制器正在接收 System.Byte[] 。 我想我没有正确发送 ascii 字符序列。

   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

试试这个:

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