/// <summary> /// Threaded Version /// </summary> private void StartSocket() { socket = IRCHandler.ConnectToTwitch("irc.chat.twitch.tv", 6667, "botjrsenior", "oauth:"); IRCHandler.SendSocket(socket, "JOIN #botjrsenior\n"); int counter = 0; do { counter++; string message = IRCHandler.ReadSocket(socket); if (message.Trim().Length > 1) { while (lockMessageList) { Thread.Sleep(10); } lockMessageList = true; messages.Add(message); lockMessageList = false; } Thread.Sleep(100); } while (continueSock && socket.Connected); socket.Close(); }
/// <summary> /// Coroutine Version /// </summary> /// <returns></returns> IEnumerator StartSocketCoRoutine() { socket = IRCHandler.ConnectToTwitch("irc.chat.twitch.tv", 6667, "botjrsenior", "oauth:"); yield return(null); IRCHandler.SendSocket(socket, "JOIN #botjrsenior\n"); yield return(null); int counter = 0; do { counter++; string message = IRCHandler.ReadSocket(socket); if (message.Trim().Length > 1) { while (lockMessageList) { yield return(new WaitForSeconds(0.01f)); } lockMessageList = true; messages.Add(message); lockMessageList = false; } yield return(new WaitForSeconds(.1f)); } while (continueSock && socket.Connected); continueSock = false; socket.Close(); }