2011-02-17 37 views
1

,我要翻譯的code的片段是在這裏:什麼是Android/Java相應的方法到C#Stream對象方法Write()?

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 
      { 
       return 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); 
     } 

回答

1

Stream.Write等效爲OutputStream.write ...但目前還不清楚這是否將足以幫助你。 (這也不清楚爲什麼你當前的代碼是使用Encoding.ASCII.GetBytes(co.ToCharArray())而不是隻有Encoding.ASCII.GetBytes(co)

+0

我很榮幸能收到你的回覆,謝謝你的幫助。編輯:我應該獲得更多關於你的問題的信息,我會在這裏發表評論。 – 2011-02-17 18:43:32

相關問題