çwinsock的"轧制解析" [英] C winsock "rolling parsing"

查看:138
本文介绍了çwinsock的"轧制解析"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从服务器接收数据并解析它。

i'm trying to receive data from a server and parse it.

http://pastebin.com/1kjXnXwq
http://pastebin.com/XpGSgRBh

http://pastebin.com/1kjXnXwq http://pastebin.com/XpGSgRBh

一切,是利国利民的,但我想分析数据,而不是仅仅抓住它的模块和打印出来。那么有没有什么办法可以抓住从winsock的数据,直到\\ n然后停止并把它传递给另一个函数来进行分析,一旦该函数返回继续从最后一个点读,直到另一个\\ n显示出来,直到有repeate过程精光接收?

everything works as is, but i want to parse the data instead of just grabbing blocks of it and printing it out. so is there any way to grab data from the winsock until \n then stop and pass it off to another function to be parsed and once that function returns continue reading from the last point until another \n shows up and repeate the process until there is nothing left to receive?

这应该是这样的功能称为msgLoop()和位于所述第二引擎收录线

the function that is supposed to be doing this is called msgLoop() and is located in the second pastebin line.

推荐答案

要读取一个套接字的 \\ n 封端的字符串,你必须要么:

To read an \n-terminated string from a socket, you have to either:


  1. 在一个时间从插座1个字节读,直到你遇到一个 \\ n 字节。任何未读的字节留在插座,直到你以后读。这是不是很有效,但它的作品。

  1. read from the socket 1 byte at a time until you encounter a \n byte. Any unread bytes are left in the socket until you read them later. This is not very efficient, but it works.

创建数据高速缓存。当你需要一个新的字符串,首先检查缓存,看看是否已经有一个 \\ n 字节$ P $它psent。如果没有,那么保持在较大块的读取套接字,并将其存储到缓存中,直到你遇到一个 \\ n 字节。然后处理缓存的内容上升到第 \\ n 字节,删除您处理的字节,移动任何剩余字节缓存前面供以后读取。

create a data cache. When you need a new string, first check the cache to see if there is already a \n byte present in it. If not, then keep reading from the socket in larger blocks and store them into the cache until you encounter a \n byte. Then process the contents of the cache up to the first \n byte, remove the bytes you processed, and move any remaining bytes to the front of the cache for later reads.

这篇关于çwinsock的"轧制解析"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆