从y Corona应用程序我发送一条消息,使用LUA Socket,它报告一切都很好(消息缩短了):
{,"Seats":{"SeatPosition":1,"Player":"FirstName":"J","LastName":"C","PlayerID":"123"}},"SeatPosition":2,"Player":"FirstName":"T","LastName":"W","PlayerID":123}},"SeatPosition":3,"Player":{"FirstName":"T","LastName":"W","PlayerID":123}}]}} - 1508 <-- Bytes sent
然后在C#服务器上我开始收到消息,如果它是一条较短的消息,它可以正常工作(就像登录消息只包含一个ID等)。
这是服务器抛出的错误消息:
PlayerClient.OnData: Exception: Newtonsoft.Json.JsonReaderException: Unterminated string. Expected delimiter: ". Path 'Table.Seats[2].Player.FirstName', line 1, position 4096.
这是OnData方法:
public void OnData(byte[] data)
{
string json = "";
try
{
var settings = new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.All
};
json = System.Text.Encoding.UTF8.GetString(data);
Console.WriteLine(json);
Command c = JsonConvert.DeserializeObject<Command>(json, settings);
}
}
catch (Exception ex)
{
Console.WriteLine("PlayerClient.OnData: Exception: " + ex.ToString());
Console.WriteLine(json);
}
}
这是切断消息的地方(前面部分已删除):
Name":"Tomas","LastName":"Westerlund","PlayerID":123}},{"SeatPosition":3,"Player":{"FirstName":"T
另一部分似乎稍后会收到:
","LastName":"W","PlayerID":123}}]}}
我可以在消息中看到数组中还有很多空间,但我仍然试图改变字节数组的大小以使其更大但没有区别。消息在同一个地方被切断。
这是收到实际消息的方式:
currentSocket = s;
//TODO: Get the actual length of the message.
byte[] data = new byte[4096];
int res = s.Receive(data);
if (res == 0)
RemoveSocket(s);
else
sockets[s].OnData(data);
知道为什么服务器没有读取整条消息?