我正在尝试使用套接字技术从在 pc 上运行的 C# 程序(服务器)将两个整数发送到 python 客户端脚本(在 Linux 机器上运行)。到目前为止,我能够发送字符串。
服务器:
TcpListener listener = new TcpListener(IPAddress.Any, 12345);
Invoke(new PrintMsg(printMsg), new object[] { "Trying to connect" });
listener.Start();
for(; ; ;)
{
TcpClient client = null;
try
{
client = listener.AcceptTcpClient();
netStream = client.GetStream();
Invoke(new PrintMsg(printMsg), new object[] { "Found client" });
//send command to client
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] buffer = encoder.GetBytes("Hello client");
netStream.Write(buffer, 0, buffer.Length);
netStream.Flush();
}
catch (Exception ex)
{
Invoke(new PrintMsg(printMsg), new object[] { ex.ToString() });
}
}
客户端代码是:
while True:
msg = s.recv(1024)
print 'SERVER:', msg
所以我想将一个整数“放入”缓冲区数组,然后将其发送到 python 脚本。可能吗?我究竟做错了什么?