Hi.
I'm using 0.9.0-beta1 version.
I try to develop client-server application and i have some questions about async methods in Msgpack:
static async Task SendData(TcpClient client) {
NetworkStream stream = client.GetStream();
var context = new SerializationContext();
context.SerializerOptions.WithAsync = true;
var serializer = context.GetSerializer<Client.PhotoEntry>();
var targetObject = new Client.PhotoEntry { id = 1, title = "My photo" };
// await serializer.PackAsync(stream, targetObject); // 1 - not packing
await serializer.PackToAsync(MsgPack.Packer.Create(stream), targetObject); // 2 - packing
}
If i use PackAsync method to pack data into Network stream, then stream is empty (method NetworkStream.DataAvailable show "false" on client).
If i use PackToAsync method with Packer.Create, then allright (method NetworkStream.DataAvailable show "true" on client).
What's wrong?
static async Task ReadData(TcpClient client) {
if(client.GetStream().CanRead) {
while(client.GetStream().DataAvailable) {
NetworkStream stream = client.GetStream();
var context = new SerializationContext();
context.SerializerOptions.WithAsync = true;
var serializer = context.GetSerializer<PhotoEntry>();
var deserializedObject = await serializer.UnpackFromAsync(MsgPack.Unpacker.Create(stream)); // result is null
// var deserializedObject = serializer.Unpack(stream); // allright
try {
Console.WriteLine("Object title=" + deserializedObject.title);
} catch {
}
}
}
}
If i use UnpackFromAsync method with Unpacker.Create, then result is null (method NetworkStream.DataAvailable show "true").
If i use simple Unpack method, then allright (console show my object data).
Where is my mistake?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4