请问我用SOCKET传递数据,,怎么才能传送中文我传的中文全是乱码,,,怎么才能传送中文呢???

解决方案 »

  1.   

    把数据流格式设置为unicode估计就可以了,你用的是ascll码,传不了中文
      

  2.   

    byte [] a = Encoding.Default.GetBytes("中文");
      

  3.   

    采用 BigEndianUnicode 编码就行了!
      

  4.   

    Imports System.Net
    Imports System.Net.Sockets
    Imports System.TextPublic Class SmsToachievement
        Inherits Sms    Private rebyte(1024) As Byte
        Private client As Socket
        Private buffer(0) As String
        <VBFixedString(4)> Private command As String    Public Function SendMsg() As String
            '发送
            '打开连接
            Dim revalues As String        revalues = MyBase.Open
            If revalues <> "ok" Then
                Return revalues
            Else
                client = MyBase.GetClient
            End If        '发送信息
            command = "A001"
            buffer(0) = command        rebyte = Encoding.GetEncoding("gb2312").GetBytes(buffer(0))
            Try
                client.Send(rebyte, rebyte.Length, 0)
            Catch ex As Exception
                Call MyBase.Dispose()
                Return "Code(03) " & ex.Message
            Finally
                rebyte.Clear(rebyte, rebyte.Length, 0)
                buffer.Clear(buffer, 0, buffer.Length)
            End Try        '读取返回值
            Return MyBase.Read(client)
        End Function
    End Class