• 请不要在回答技术问题时复制粘贴 AI 生成的内容
mantianyu
V2EX  ›  程序员

socket 编程 recv 调用能否每次最多读一行?

  •  
  •   mantianyu · Dec 9, 2013 · 3770 views
    This topic created in 4587 days ago, the information mentioned may be changed or developed.
    When communicating with serial port, I can set the serial port in Canonical Mode so that each read() call will return util a line comes, and at most one line.

    assumes the line separator is \r\n.

    Does TCP/IP communication support this feature?

    I know that TCP/IP is based on stream and will take 'a','b','c' and '\r','\n' all the same, but I really don't want to parse the message char by char to find '\r','\n' in application.

    I hope the TCP can do it for me...

    any idea?
    7 replies    1970-01-01 08:00:00 +08:00
    binux
        1
    binux  
       Dec 9, 2013
    do it yourself
    bigeagle
        2
    bigeagle  
       Dec 9, 2013
    This is definitely application logic, which TCP should not handle.

    So keep calm and implement it yourself.
    VYSE
        3
    VYSE  
       Dec 9, 2013
    socket.makefile
    then readline
    rrfeng
        4
    rrfeng  
       Dec 9, 2013
    while ‘\r\n’ not in data
    data+=recv()
    mantianyu
        5
    mantianyu  
    OP
       Dec 9, 2013
    @binux
    @bigeagle
    @VYSE
    @rrfeng

    谢谢大家^_^
    sgissb1
        6
    sgissb1  
       Dec 9, 2013
    ni hao !

    ni wei shen me zhe me diao ?

    ni wei shen me yao mei ci du yi hang?
    bombless
        7
    bombless  
       Dec 10, 2013
    噗,肯定要缓存结果的,TCP是8位流又不是数据包。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3331 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 10:54 · PVG 18:54 · LAX 03:54 · JFK 06:54
    ♥ Do have faith in what you're doing.