Java套接字没有收到确切的消息

时间:2015-04-03 08:15:12

标签: java c# sockets socket.io serversocket

我在c#中从Android设备向服务器应用程序发送消息...我已经成功地从移动设备发送了消息并收到了服务器,但是在移动设备上没有以原始形式收到来自服务器的消息。 。

用于发送消息的C#代码

         if (message == "Share_Screen")
          {
            string msg = "Go to java Socket in Android";

            byte[] bfr = Encoding.ASCII.GetBytes(msg);
            MessageBox.Show("No of bytes to be send are "+bfr.Length);
            socket.Send(bfr);
          }

发送和接收单个邮件的Java代码

        try
        {

            Socket socket = new Socket(ip,5353);
            byte[] receiverBuffer = new byte[28];
            byte[] buffer = "Share_Screen".getBytes();

            DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
            dataOutputStream.write(buffer,0,buffer.length);

            //sending successfully this message to c# socket
            DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
            dataInputStream.read(receiverBuffer);

            String msg = receiverBuffer.toString();

            dataOutputStream.close();
            dataInputStream.close();
            socket.close();
            return msg;
            //expected message is " Go to java Socket in Android "
            //received message is " |b@52a5395c "
        }
        catch (IOException e)
        {
            return "error";
        }
在Android设备中接收的

消息就像“| b @ 52a5395c”

0 个答案:

没有答案