I wrote a Twitch Chat Bot wrapper for a game so that a group of friends can play the game as a team from Twitch. It runs on Ubuntu. It is all working but I need to add code to handle a Twitch reconnect message. I have three questions:
1: After receiving the reconnect message can the code immediately send a message to the chat to inform the players that a reconnect is about to take place? For example could I send “Reconnect in progress, please wait”. Or will the socket connection be closed by the Twitch end very quickly after sending the reconnect message?
2: Assuming that I cannot do question 1, What do the players see in their chat windows, after Twitch has sent the reconnect and closes the socket connection?
3: I believe the flow of the reconnect is as follows:
Close the socket,
Open a new socket
Authenticate with Twitch.
Continue the game.
Is this correct?
Again, thanks for the reply. I see you help a lot of members asking question. So thanks!!!
One last question. Any thoughts on how I can test that my reconnect code works. One idea I had was to just leave the bot running for a extended period of time and wait until Twitch needs to do maintenance on the server. My code at this time is logging all interaction with Twitch, so I will see the reconnect messages in the log and the result of doiing the reconnect code. But this seems like a kludge.
DevMcGee and BarryCrayon,
Thank again both of you for taking the time to reply. Both your replies made me realized that I have a way to test this. For the Twitch chat bot wrapper that I wrote for the game, I needed to test for a large number of players that were playing as a team. I did not want to create a large number of Twitch accounts for this, so I wrote a Twitch simulator that connects to Chat Bot via a socket. I can enhance the simulator to randomly close the socket (for non Twitch network issues) and also to randomly send a RECONNECT message and then close the socket.
Below I put a little write up on the Twitch chat bot wrapper and the Twitch simulator. Just ignore this if it is not of interest.
The games Twitch Chat Bot wrapper handles all the communication needed for Twitch. It also has a voting section. Within a "time slice, it could receive multiple commands from the users. Some may type in “do A” other “do B”, etc. The voting code looks at all the commands received within the “time slice” and passes the one with the most votes to the game.
The Twitch simulator send messages that look exactly like Twitch messages. It sets up a number of users based on a define and then accepts a command string of up to 4 commands. It then spread these commands across all the defined number of users and then randomly select a user and sends their command to the Chat Bot. It does this until it has sent a command for every user. It then gets the next set of commands. I was able to simulator more then 400 users before the commands started been received outside the “time slice”. At 700 users some commands come in when the next “time slice” opened. I could make the time slice larger and go much higher with the number of users.