Пример: sockettest
Скрипт для примера работы класса socket
Примечание: из-за работы в другом текстовом редакторе, здесь отсутствуют отступы в блоках if-else
Исходный код
- sockettest.lua
use, "socket" socket:listen, ":2525" server = returned ::repeataccept socket:accept, server sock = returned print, "Received connection!" socket:write, sock, "Hello\n" ::repeatreading socket:read, sock data = returned if data == "Hello" socket:write, sock, "Nice to meet you\n" elif data == "Shutdown" sockexit, sock, server elif data == "Exit" socket:write, sock, "Goodbye!\n" jump, "exitfromsock" end jump, "repeatreading" ::exitfromsock socket:close, sock jump, "repeataccept" <<sockexit, sock, server socket:write, sock, "Shutting down!\n" socket:close, sock socket:destroy, server print, "Shutting down" exit, 0 >>