Netty服务器和C#套接字客户端。在客户端接收不起作用

时间:2014-04-13 18:57:04

标签: c# sockets netty tcpclient protobuf-net

我想从Netty服务器接收C#客户端上的消息。我使用sync C#socket和protobuf。 我发送消息给服务器,没关系。但我无法收到回复。 Netty服务器使用ProtobufDecoder。 Server ChannelInboundHandler有这部分代码:

 public void channelRead0(final ChannelHandlerContext ctx, Object msg) {
        ...
            Set<String> keys = jedis.keys("tanks*");

            String allKeys = "";
            for(String key: keys){
                allKeys+=key+";";
            }

            ctx.write(allKeys);
            ctx.flush();
}

C#客户端代码是:

 const string server = "localhost";
const int port = 8080;
var tcpClient = new TcpClient(server, port);
_networkStream = tcpClient.GetStream();

var stream = new MemoryStream();
Serializer.Serialize(stream, tankDataObject);
var data = stream.ToArray();
_networkStream.Write(data, 0, data.Length);

data = new Byte[10000];

// String to store the response ASCII representation.
String responseData = String.Empty;

// Read the first batch of the TcpServer response bytes.
Int32 bytes = _networkStream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

// Close everything.
_networkStream.Close();
tcpClient.Close();

如果我在服务器上调用ctx.close(),客户端不会收到任何字节或接收空数组。任何帮助将不胜感激。谢谢。

0 个答案:

没有答案