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.
Sockets and Threads
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Sockets and Threads
Not really. But can't you just do all the socket-stuff in a thread, then send the data back instead? Also, the way to work with luasocket asynchronously is using either socket.select or setting the timeout to 0.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Sockets and Threads
As bartbes said, you'd want to pass the messages you want to send via sockets, and the stuff you get back, through channels; those should be either strings, or flat tables (containing strings and numbers and bools at most).
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
- Prole
- Posts: 5
- Joined: Mon Dec 28, 2015 3:37 pm
Re: Sockets and Threads
I was originally wanting to send messages to the IRC channel in addition to receiving them, but now that I think of it, I could just send those from the thread as well. Thanks for the help.
Re: Sockets and Threads
How did you login to an account with Love?
Who is online
Users browsing this forum: No registered users and 0 guests