Python1320

OOSocks Bin test

Aug 15th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. local SOCK_ERROR = {}
  2. SOCK_ERROR[SCKERR_OK]                   = "SCKERR_OK"
  3. SOCK_ERROR[SCKERR_BAD]                  = "SCKERR_BAD"
  4. SOCK_ERROR[SCKERR_CONNECTION_RESET]     = "SCKERR_CONNECTION_RESET"
  5. SOCK_ERROR[SCKERR_NOT_CONNECTED]        = "SCKERR_NOT_CONNECTED"
  6. SOCK_ERROR[SCKERR_TIMED_OUT]            = "SCKERR_TIMED_OUT"
  7.  
  8. local Calltypes = {
  9.     [SCKCALL_CONNECT] = "Connect", -- SCKCALL_CONNECT
  10.     [SCKCALL_REC_SIZE] = "Rec Size", -- SCKCALL_REC_SIZE
  11.     [SCKCALL_REC_LINE] = "Rec Line", -- SCKCALL_REC_LINE
  12.     [SCKCALL_SEND] = "Send", -- SCKCALL_SEND
  13.     [SCKCALL_BIND] = "Bind", -- SCKCALL_BIND
  14.     [SCKCALL_ACCEPT] = "Accept", -- SCKCALL_ACCEPT
  15.     [SCKCALL_LISTEN] = "Listen", -- SCKCALL_LISTEN 
  16.     [SCKCALL_REC_DATAGRAM] = "Datagram", -- SCKCALL_REC_DATAGRAM
  17. }
  18.  
  19.  
  20. local con = OOSock(IPPROTO_TCP)
  21. if _G.con then print("Closing:", _G.con:Close()) end
  22. _G.con=con
  23. local function Received(data, sock, call, id, error, binread, peer, port)
  24.     print("\tData: '"..tostring(data).."'")
  25.     local derp=BinWrite()
  26.     derp:WriteString"Test!!\n"
  27.     con:Send(derp)
  28. end
  29.  
  30. con:SetCallback(function(sock, call, id, error, binread, peer, port)
  31.     if(error != SCKERR_OK) then
  32.         ErrorNoHalt("Error (" .. SOCK_ERROR[error].. "/" .. Calltypes[call] .. ")\n")
  33.         sock:Close()
  34.         return
  35.     end
  36.         if call == SCKCALL_REC_LINE then
  37.             local size = binread:GetSize()
  38.             print("Got binread, size:",size)
  39.             local data = ""
  40.                  
  41.             for i=1, size do
  42.                 data = data .. string.char(binread:ReadByte())
  43.             end
  44.             Received(data, sock, call, id, error, binread, peer, port)
  45.             sock:ReceiveLine()
  46.         elseif call==SCKCALL_REC_SIZE then
  47.             Received(binread, sock, call, id, error, binread, peer, port)
  48.             sock:ReceiveLine()
  49.            
  50.         elseif call==SCKCALL_CONNECT then
  51.             print(sock,"connected")
  52.             sock:ReceiveLine()
  53.         else
  54.             print("unhandled callback: " .. Calltypes[call] .. ".")
  55.         end
  56.        
  57. end)
  58. con:SetBinaryMode( true )
  59. con:Connect("iriz.org", 6667)
Advertisement
Add Comment
Please, Sign In to add comment