Search code examples
socketslualuasocket

lua socket receive reports same data multiple times


I have the following code which sits inside a loop (Simplified). cscc is a client socket connecting to a server on localhost. My server sends a single character to the client. However, I don't seem to be receiving it properly. Protocol is TCP.

    rect, _, st = socket.select({cscc}, nil, .5)

    if(rect[cscc] ~= nil) then
        data, err, part = csc:receive(512)
        if(part ~= nil) then
            print(err.." : "..part)
        end
        socket.sleep(1)
    end

When the character is sent from the server, I get the following line repeating as output:

timeout :

obviously, part is not null here. What is going on here? Why am I receiving the same thing over and over?


Solution

  • Perhaps the server never got to really send any data at all. Check if part is non empty and see what happens if you don't pass the third parameter to socket.select.