开发者

What is the Android/Java corresponding method to the C# Stream object method Write()?

开发者 https://www.devze.com 2023-02-11 07:12 出处:网络
A snippet of the code that I want to translate is here: class MK { Stream connection; TcpClient con; public MK(string ip)

A snippet of the code that I want to translate is here:

class MK
    {   
        Stream connection;
        TcpClient con;

        public MK(string ip)
        {
            con = new TcpClient();
            con.Connect(ip, 8728);
            connection = (Stream)con.GetStream();
        }
        public void Close()
        {
            connection.Close();
            con.Close();
        }
        public bool Login(string username, string password)
        {
            Send("/login", true);
            string hash = Read()[0].Split(new string[] { "ret=" }, StringSplitOptions.None)[1];
            Send("/login");
            Send("=name=" + username);
            Send("=response=00" + EncodePassword(password, hash), true);
            if (Read()[0] == "!done")
            {
                return true;
            }
            else
            {
                re开发者_Go百科turn false;
            }
        }
        public void Send(string co)
        {
            byte[] bajty = Encoding.ASCII.GetBytes(co.ToCharArray());
            byte[] velikost = EncodeLength(bajty.Length);

            connection.Write(velikost, 0, velikost.Length);
            connection.Write(bajty, 0, bajty.Length);
        }
        public void Send(string co, bool endsentence)
        {
            byte[] bajty = Encoding.ASCII.GetBytes(co.ToCharArray());
            byte[] velikost = EncodeLength(bajty.Length);
            connection.Write(velikost, 0, velikost.Length);
            connection.Write(bajty, 0, bajty.Length);
            connection.WriteByte(0);
        }


The equivalent of Stream.Write is OutputStream.write... but it's not clear whether that will be enough to help you. (It's also not clear why your current code is using Encoding.ASCII.GetBytes(co.ToCharArray()) instead of just Encoding.ASCII.GetBytes(co)

0

精彩评论

暂无评论...
验证码 换一张
取 消