我的问题是,在我连接到IRC并且我从IRC接收原始文本并记录它之后,它只是决定在不活动后或在我启动后2-3秒(未经证实)与服务器断开连接。
任何帮助,将不胜感激。 这是我的代码(有问题在这里发布): http : //pastebin.com/Ls5rv0RP
我需要它来停止断开,但我真的找不到办法。 我知道流行的mIRC客户端在x时间后与Twitch断开连接但重新连接,只要它知道及时重新连接(2-5秒)就可以了。
这部分是回复PING / PONG的:
if (buf.StartsWith("PING ")) output.Write(buf.Replace("PING", "PONG") + "\r\n"); output.Flush();任何帮助表示赞赏。
My issue is that after I connect to the IRC and I am receiving raw text from the IRC and logging it but then it just decides to disconnect from the server after inactivity or 2-3 seconds after I start it (unconfirmed).
Any help would be appreciated. Here's my code (had issues posting it here): http://pastebin.com/Ls5rv0RP
I need it to stop disconnecting but I cant really find a way to. I know the popular mIRC client disconnects from Twitch after x amount of time but reconnects and that's fine to as long as it KNOWS to reconnect in a timely manner (2-5 seconds).
The part were it replys to PING/PONG's:
if (buf.StartsWith("PING ")) output.Write(buf.Replace("PING", "PONG") + "\r\n"); output.Flush();Any help is appreciated.
最满意答案
下面的代码通过运行一个ping到IRC服务器的单独线程来帮助防止我的Twitch bot断开连接。
PingSender类:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace TwitchBot { /* * Class that sends PING to irc server every 5 minutes */ class PingSender { static string PING = "PING "; private Thread pingSender; // Empty constructor makes instance of Thread public PingSender() { pingSender = new Thread (new ThreadStart (this.Run) ); } // Starts the thread public void Start() { pingSender.Start(); } // Send PING to irc server every 5 minutes public void Run() { while (true) { Program.irc.sendIrcMessage(PING + "irc.twitch.tv"); Thread.Sleep(300000); // 5 minutes } } } }用法:
/* Ping to twitch server to prevent auto-disconnect */ PingSender ping = new PingSender(); ping.Start();This code below helps keep my Twitch bot from disconnecting by running a separate thread that pings to the IRC server.
PingSender Class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace TwitchBot { /* * Class that sends PING to irc server every 5 minutes */ class PingSender { static string PING = "PING "; private Thread pingSender; // Empty constructor makes instance of Thread public PingSender() { pingSender = new Thread (new ThreadStart (this.Run) ); } // Starts the thread public void Start() { pingSender.Start(); } // Send PING to irc server every 5 minutes public void Run() { while (true) { Program.irc.sendIrcMessage(PING + "irc.twitch.tv"); Thread.Sleep(300000); // 5 minutes } } } }Usage:
/* Ping to twitch server to prevent auto-disconnect */ PingSender ping = new PingSender(); ping.Start();更多推荐
发布评论