Java GBK编码和PHP

时间:2014-05-07 14:39:12

标签: java php char

以下代码是我需要转换为Java以将其写入套接字连接的PHP代码

$info = chr(6).chr(0).chr(255).chr(255).'info'; 

在PHP上,它与此代码完美配合

$Socket = fsockopen($this->Host, $this->Port, $errno, $errstr, 5);
fwrite($Socket, chr(6).chr(0).chr(255).chr(255).'info');

我试过这个

public static void main(String[] args) {

        char a = 6;
        char b = 0;
        char c = 255;


        try {

            Socket test = new Socket("shadowcores.twifysoft.net", 7171);
            BufferedWriter write = new BufferedWriter(new OutputStreamWriter(test.getOutputStream()));

            write.write(Character.toString(a) + "." + Character.toString(b) + "." + Character.toString(c) + "." +  Character.toString(c)  + "." +  "info");
            BufferedReader read = new BufferedReader(new InputStreamReader(test.getInputStream()));
            System.out.println(read.read());
            test.close();

        } catch (IOException e) {

            e.printStackTrace();

        }
    }

没有成功,因为我应该在将消息写入服务器后从服务器获取一些信息 如何将该PHP字符串转换为Java字符串?

0 个答案:

没有答案