这就是我的意思:
put 512 bytes
SocketChannel#write(this data)
start at the beginning and put 512 bytes again
rinse & repeat
Run Code Online (Sandbox Code Playgroud)
我仍然试图掌握ByteBuffers并尝试使用ByteBuffer#reset()但我总是得到一个InvalidMarkException,即使这似乎是正确的解决方案(除非我错了,我不会感到惊讶!)
谢谢!
编辑:具体来说,我正在尝试实现同样的效果,除了我想以512字节块而不是批量发送它. http://privatepaste.com/1fb0e6df07
我想使用JavaScriptSerializer发送一个JSON数据包,其中包含一个对象列表以及一个标识为ChatLogPath的字符串.据我所知,该类只能序列化一个对象 - 作为列表 - 如果我尝试追加多个对象,它显然只会创建无效的JSON,如{...} {...}工作.
有没有办法做到这一点?我是C#和ASP.NET MVC的新手,所以请原谅我,如果这是一个愚蠢的问题:)
编辑:这是我现在的代码.
string chatLogPath = "path_to_a_text_file.txt";
IEnumerable<ChatMessage> q = ...
...
JavaScriptSerializer json = new JavaScriptSerializer();
return json.Serialize(q) + json.Serialize(chatLogPath);
Run Code Online (Sandbox Code Playgroud)
这将在JSON {...}中输出这样的数组,然后是chatLogPath {...}.换句话说,它无法工作,因为那是无效的JSON.