local sampev=require("samp.events")
local copas = require('copas')
local neatJSON = require('neatjson')
local json = require('cjson')
local websocket = require'websocket'
newCoro = Tasking.new
local client = websocket.client.copas({timeout=10})
function Main()
local ok, err = client:connect('ws://localhost:5000', 'echo')
if ok then
print('connected')
local message = {
username = getNick(),
id = 14,
event = 'connection'
}
local json = neatJSON(message, {wrap = false})
local ok = client:send(json)
end
if not ok then
print('***********************************************could not connect***********************************************', err)
end
-- **************************************************************************************************************************************************
newCoro(function ()
while true do
local message = client:receive()
if message then
print('msg',message)
else
print('connection closed')
end
end
end)
end
copas.addnamedthread('connection', function ()
Main()
end)
copas()