我要翻译的code代码段在这里:
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);
}
答案 0 :(得分:1)
Stream.Write
相当于OutputStream.write
......但目前尚不清楚这是否足以帮助您。 (目前还不清楚为什么您当前的代码使用的是Encoding.ASCII.GetBytes(co.ToCharArray())
,而不仅仅是Encoding.ASCII.GetBytes(co)