0

I'm wondering if there's a way to see when the client sends a packet, what header it sends, and how I can deal with it. If in instance, a client sends a header like : 0xAA, how would I reply to that?

This is what I currently have.

socket = require("socket")
server = assert(socket.bind("*", 11000))
ip, port = server:getsockname()

while true do
  local client = server:accept()
  client:settimeout(0)
  client:send(string.char(0xEC,0x2C,0x4A,0x00)) -- Reply
end

What I'm looking for is when the connected client sends an packet, the server reads the header, and I can choose what packet I wish to send back (the reply is sent instantly when a client connects)

Xhalo7
  • 1
  • 3
  • Does `client` have a `receive` method? That sounds useful... – Diego Apr 04 '15 at 18:29
  • Yes. But I'm clueless on seeing what the client has sent to the Server. I even tried print(client:recieve), but I got nil as response. While, on a packet sniffer, I can clearly see that the client did send data. – Xhalo7 Apr 04 '15 at 18:31
  • 2
    Ok..according to the documentation, in case `nil` is returned the method also returns an error message. Do something like `msg, err = client:receive()` and print `err` to see what's happening. – Diego Apr 04 '15 at 18:39
  • Oh, alright. Seems that I made a mistake somewhere in my code. I can now read the data being sent from the client. I'll mark this as solved. – Xhalo7 Apr 04 '15 at 18:47

0 Answers0