Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SOCK_ERROR = {}
- SOCK_ERROR[SCKERR_OK] = "SCKERR_OK"
- SOCK_ERROR[SCKERR_BAD] = "SCKERR_BAD"
- SOCK_ERROR[SCKERR_CONNECTION_RESET] = "SCKERR_CONNECTION_RESET"
- SOCK_ERROR[SCKERR_NOT_CONNECTED] = "SCKERR_NOT_CONNECTED"
- SOCK_ERROR[SCKERR_TIMED_OUT] = "SCKERR_TIMED_OUT"
- local Calltypes = {
- [SCKCALL_CONNECT] = "Connect", -- SCKCALL_CONNECT
- [SCKCALL_REC_SIZE] = "Rec Size", -- SCKCALL_REC_SIZE
- [SCKCALL_REC_LINE] = "Rec Line", -- SCKCALL_REC_LINE
- [SCKCALL_SEND] = "Send", -- SCKCALL_SEND
- [SCKCALL_BIND] = "Bind", -- SCKCALL_BIND
- [SCKCALL_ACCEPT] = "Accept", -- SCKCALL_ACCEPT
- [SCKCALL_LISTEN] = "Listen", -- SCKCALL_LISTEN
- [SCKCALL_REC_DATAGRAM] = "Datagram", -- SCKCALL_REC_DATAGRAM
- }
- local con = OOSock(IPPROTO_TCP)
- if _G.con then print("Closing:", _G.con:Close()) end
- _G.con=con
- local function Received(data, sock, call, id, error, binread, peer, port)
- print("\tData: '"..tostring(data).."'")
- local derp=BinWrite()
- derp:WriteString"Test!!\n"
- con:Send(derp)
- end
- con:SetCallback(function(sock, call, id, error, binread, peer, port)
- if(error != SCKERR_OK) then
- ErrorNoHalt("Error (" .. SOCK_ERROR[error].. "/" .. Calltypes[call] .. ")\n")
- sock:Close()
- return
- end
- if call == SCKCALL_REC_LINE then
- local size = binread:GetSize()
- print("Got binread, size:",size)
- local data = ""
- for i=1, size do
- data = data .. string.char(binread:ReadByte())
- end
- Received(data, sock, call, id, error, binread, peer, port)
- sock:ReceiveLine()
- elseif call==SCKCALL_REC_SIZE then
- Received(binread, sock, call, id, error, binread, peer, port)
- sock:ReceiveLine()
- elseif call==SCKCALL_CONNECT then
- print(sock,"connected")
- sock:ReceiveLine()
- else
- print("unhandled callback: " .. Calltypes[call] .. ".")
- end
- end)
- con:SetBinaryMode( true )
- con:Connect("iriz.org", 6667)
Advertisement
Add Comment
Please, Sign In to add comment