probable-basilisk / pollnet Goto Github PK
View Code? Open in Web Editor NEWPolling-based C api networking library designed for easy FFI use
License: MIT License
Polling-based C api networking library designed for easy FFI use
License: MIT License
I'm having some issues trying to use websockets with pollnet. So here I've got a simple echo server:
local pollnet = require("pollnet")
local sock = pollnet.listen_ws("ws://127.0.0.1:12347")
while true do
if not sock then return end
local happy, msg = sock:poll()
if not happy then
print("closing sock")
sock:close() -- good form to avoid keeping listen_sockets open
sock = nil
os.exit()
else
print("happy")
end
if msg then
sock:send(msg)
end
end
But this is what it prints:
$ ./luajit.exe wsserv.lua
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
happy
closing sock
Hi!
I'm using the latest Pollnet 1.0.1 with liajit and I observe some strange behavior. The code is
local pollnet = require("pollnet")
local url = "wss://irc-ws.chat.twitch.tv:443"
local sock = pollnet.open_ws(url)
local sock_status = nil
repeat
local happy, msg = sock:poll()
local new_status = sock:status()
print("*** " .. new_status)
if new_status ~= sock_status then
print(msg)
end
sock_status = new_status
pollnet.sleep_ms(300)
until not happy
And I get the following output (note the status changes opening
-> open
-> opening
):
*** opening
nil
*** opening
*** opening
*** open
nil
*** opening
nil
*** opening
*** opening
*** opening
This changes a bit if I send PASS and NICK commands to twitch when the status becomes open
:
local pollnet = require("pollnet")
local url = "wss://irc-ws.chat.twitch.tv:443"
local sock = pollnet.open_ws(url)
local sock_status = nil
repeat
local happy, msg = sock:poll()
local new_status = sock:status()
print("*** " .. new_status)
if new_status ~= sock_status then
print(msg)
if sock_status == "open" then
sock:send("PASS nopass")
local anon_user_name = "justinfan" .. math.random(1, 100000)
sock:send("NICK " .. anon_user_name)
end
end
sock_status = new_status
pollnet.sleep_ms(300)
until not happy
The output:
*** opening
nil
*** opening
*** opening
*** open
nil
*** opening
nil
*** opening
*** open
:tmi.twitch.tv 001 justinfan79421 :Welcome, GLHF!
:tmi.twitch.tv 002 justinfan79421 :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 justinfan79421 :This server is rather new
:tmi.twitch.tv 004 justinfan79421 :-
:tmi.twitch.tv 375 justinfan79421 :-
:tmi.twitch.tv 372 justinfan79421 :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 376 justinfan79421 :>
*** open
*** open
The socket ends up in the open
state but it still returns to opening
for some time.
I'm using LuaJIT built from the master branch with MSYS/MinGW64 and pollnet is from the latest 1.0.1 release zip 64-bit Windows.
Hello,
I have followed the examples which state that for example an http get should contain 2 messages, one being the status code and the other being the body.
I was trying to get a file from github but the body arrives as the first message. I have tried to wait until more messages arrive as well to see if the order is not flipped but on the second poll call the socket is already closed. Tested even without any manual socket closing and just looping poll on each game tick to see what it receives and the only thing I ever receive is just the body.
Am I missing something or is there currently no way to get an http status code ?
Thanks in advance.
This is not actually an issue, but a request for documentation/example.
Is it possible to access HTTP request data when serving HTTP?
how to use pollnet.dll in vc++ and excel vba create websocket server/CLIENT
DO YOU HAVE A sample,thank you
Private Declare Function pollnet_listen_ws Lib "pollnet.dll" () As Long
Private Declare Function pollnet_open_ws Lib "pollnet.dll" () As Long
Private Declare Function pollnet_close Lib "pollnet.dll" () As Long
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.