Lua TCP Server

kngsly

Новичок
Автор темы
8
0
Версия MoonLoader
.027.0-preview
How to make a simple tcp server in lua?
 

RedHolms

Известный
553
304
You can make it using FFI and winsock
Lua:
ffi = require 'ffi'

AF_INET = 2
SOCK_STREAM = 1

ffi.load("Ws2_32.dll") -- DLL with net functions
ffi.cdef[[
    int __stdcall socket(int family, int type, int protocol);
]]

local sd = ffi.C.socket(AF_INET, SOCK_STREAM, 0)
-- do bind, listen, accept and transfer data

Check winsocket tutorial on MSDN ( https://docs.microsoft.com/en-us/windows/win32/winsock/getting-started-with-winsock ), you can use the same functions in lua using FFI (note all of them is stdcall)
 
  • Нравится
Реакции: kngsly