Sockets and Threads
Posted: Mon Feb 22, 2016 7:55 am
Hi everyone,
I'm trying to create a simple Twitch bot with LÖVE2D. I have a working one that simply connects to an IRC channel and prints the messages, but the problem is that it is frozen for the majority of the time. LuaSockets (the sockets library I'm using), and I assume most socket libraries, wait for a response from the server before continuing execution. This is a problem because it means my drawing is delayed by the time-out from the response. I guess I could set a very small time-out but I feel like using threads would be a better way to accomplish this.
The issue I'm having with running this on a thread is that (as far as I know and have experienced) channels can only send basic data types like booleans, numbers, strings, (flat) tables, etc. LuaSockets works by you creating a TCP client, connecting the client to the server, and then sending/receiving data. I'm not exactly sure what the TCP client is, I assume it's a (non-flat) table. Whatever it is, my program stops responding if I try to demand it from a channel. What I'm wondering is if there is any possible way for me to share this client between the main code and the thread's code.
I'm trying to create a simple Twitch bot with LÖVE2D. I have a working one that simply connects to an IRC channel and prints the messages, but the problem is that it is frozen for the majority of the time. LuaSockets (the sockets library I'm using), and I assume most socket libraries, wait for a response from the server before continuing execution. This is a problem because it means my drawing is delayed by the time-out from the response. I guess I could set a very small time-out but I feel like using threads would be a better way to accomplish this.
The issue I'm having with running this on a thread is that (as far as I know and have experienced) channels can only send basic data types like booleans, numbers, strings, (flat) tables, etc. LuaSockets works by you creating a TCP client, connecting the client to the server, and then sending/receiving data. I'm not exactly sure what the TCP client is, I assume it's a (non-flat) table. Whatever it is, my program stops responding if I try to demand it from a channel. What I'm wondering is if there is any possible way for me to share this client between the main code and the thread's code.