Bot dont get incomming messages after x minutes

Hey guys, i have the following situation:
i connect (with a java lib) into the twitch chat and have no problems.
after a few minutes i dont get any incomming message. the bot is always connectet to twitch and can send messages into the chat (al other can see it) but all messages from other (public chat or whisper) dont get to the bot.

have you any idea? :frowning:

Are you sure that the incoming message thread is still running? Something might cause the incoming thread to stop (exceptions it the similar) while the sending thread is still running.

What library are you using?

iā€™m not sureā€¦ i debug all possible on-method for messages of the lib but dont get anything :confused:

i use the PircBot lib

Are you still receiving PINGs?

yes i getā€¦ but after halb an hour wothout incomming message i dont get any pingā€¦ but this problem i think is an effect of the main problem with no incomming messageā€¦

Do you send PONGs? If you do not respond to the PINGs, youā€™ll get disconnected what would explain your issue.

And messages in twitch-chat are sent as Privmsg to the bot, make sure you are listening to them and not to some public messages, idk how the pircbot interface handles those.

Do you mind sharing your java source code? I suppose the issue is somewhere in there. If you do not find success with your current library I would suggest writing your own code to connect to the servers, there are plenty of guides on how to do that.

the lib send pong by himself, but i checked and on each ping form twitch the lib send pong back
but sometimes i knog the time between the pings are so longā€¦ at the begining i get even disconnect a few seconds befor i get a pingā€¦ but last time i dont have this anymore

iā€™ll try to write my own code but iā€™m to stubed for it :confused: it never workā€¦ thats the reson i use a external lib

Well using a library for that is the common way to go, why rewrite code that already exists. But it would help a lot if you would share the part of code you have written, where the connection is established, used and maintained.

You can try my chat library if it works better. No use writing it all by yourself.

There is nothin spezial

package irc;


// ##### CLASS #####
public class IrcPircBot extends PircBot {
    public String channel = null;
    public String server = null;
    public String login = null;
    public String pass = null;
    public String nick = null;

    public void start() {
        setOutputMsg("~Login as " + nick);
        this.setName(nick);
        this.setLogin(login);
    }

    public void setOutputMsg(String message) {
        System.out.println(message);
    }

    public void login() throws NickAlreadyInUseException, IOException, IrcException {
        setOutputMsg("~Connect to server " + server);
        createConnect();
    }

    protected void createConnect() throws NickAlreadyInUseException, IOException, IrcException {
        if (this.pass != null || this.pass.isEmpty()) {
            this.connect(server, port, pass);
        } else {
            this.connect(server);
        }
    }

    protected void joinAllSubChannel() {
        sendRawLine("CAP REQ :twitch.tv/membership\r\n");     // NAMES, JOIN, PART & MODE
        sendRawLine("CAP REQ :twitch.tv/tags\r\n");         // PRIVMSG, USERSTATE, NOTICE &  GLOBALUSERSTATE
        sendRawLine("CAP REQ :twitch.tv/commands\r\n");     // USERSTATE, GLOBALUSERSTATE, ROOMSTATE, HOSTTARGET, NOTICE & CLEARCHAT
    }

    public void joinChannel() {
        setOutputMsg("~Join channel " + channel);
        this.joinChannel(channel);
        joinAllSubChannel();
    }
}


// ##### CALL CLASS #####
try {
    IrcPircBot irc = new IrcPircBot();
    irc.nick     = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
    irc.login     = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
    irc.pass     = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
    irc.channel = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
    irc.start();
    irc.login();
    irc.joinChannel();
} catch (Exception e) {
    System.out.println( e.getMessage() );
}

hm, this does not really help much tbh, since basically everything is hidden in the library calls. The only thing i can see, is that i can not see anything what would process any input, but i guess you have that somewhere? You should also make sure you are listening to Privmsg and not something else there.
Only alternative if you can not figure it out is using another library.

Another alternative would be sharing the whole code to debug it, but i guess thats no what you want to :smiley:

that is allā€¦
each incomming message will be call the ā€˜setOutputMsg()ā€™ method from the lib ā€˜PircBotā€™ (see class extends)

the class call is at the bottom of the scrollbox unter ā€œ##### CALL CLASS #####ā€
all other do the ā€œPircBotā€ libā€¦

uhhā€¦no xd actually pircbot calls ā€œonMessage()ā€ - nothing in your current code calls ā€œsetOutputMsgā€ except the one in ā€œjoinChannelā€. Thats at least how all the pircbot examples work.

Edit: and by the way, for your own sake, remove those public attributes and write some proper getters and setters, it hurts. Or even better, pass them at the constructor

yesturday iā€™ll try the code at the bottom of this postā€¦ it lost at the same time like the other botā€¦
i dont know what it is but i think itā€™s a problem on my siteā€¦ more on twitch site but dont knowā€¦

package testing;

import java.io.*;
import java.net.*;

public class irc  
{
    public String server = "";
    public String nick = "";
    public String login = "";
    public String channel = "";
    public String pass = "";

    private BufferedWriter writer = null;
    private BufferedReader reader = null;
    private String line = null;
    
    
    public void sendRawLine(String line) {
        try {
            writer.write(line);
            writer.flush();
        } catch (IOException e) {}
    }
    
    public void useDefault() {
        server = "irc.freenode.net";
        nick = "simple_bot";
        login = "simple_bot";
        channel = "#irchacks";    
    }
    
    public boolean login() throws Exception {
        // Connect directly to the IRC server.
        System.out.println("try to login");
        
        @SuppressWarnings("resource")
        Socket socket = new Socket(server, 6667);
        writer = new BufferedWriter( new OutputStreamWriter(socket.getOutputStream()) );
        reader = new BufferedReader( new InputStreamReader(socket.getInputStream()) );
        
        // Log on to the server.
        if (!pass.isEmpty()) {
            System.out.println("using pass: "+pass);
            sendRawLine("PASS " + pass + "\r\n");
        }
        
        if (!nick.isEmpty()) {
            System.out.println("using nick: "+nick);
            sendRawLine("NICK " + nick + "\r\n");            
        }

        if (!login.isEmpty()) {
            System.out.println("using login: "+login);
            sendRawLine("USER " + login + " 8 * : Java IRC Hacks Bot\r\n");
        }
        
        // Read lines from the server until it tells us we have connected.
        line = null;
        while ((line = reader.readLine( )) != null) {
            System.out.println("loop " + line);
            if (line.indexOf("004") >= 0) {
                // We are now logged in.
                System.out.println("Login success.");
                break;
            } else if (line.indexOf("433") >= 0) {
                System.out.println("Nickname is already in use.");
                return false;
            }
        }
        return true;
    }
    
    public void join() throws Exception {
        // Join the channel.
        if (!channel.isEmpty()) {
            sendRawLine("JOIN " + channel + "\r\n");        
            sendRawLine("CAP REQ :twitch.tv/membership\r\n");
            sendRawLine("CAP REQ :twitch.tv/tags\r\n");
            sendRawLine("CAP REQ :twitch.tv/commands\r\n");
        }
    }
    
    public void start() throws Exception {
        // Keep reading lines from the server.
        while ((line = reader.readLine( )) != null) {        
            if (line.trim().toUpperCase().startsWith("PING ")) {
                // We must respond to PINGs to avoid being disconnected.
                sendRawLine("PONG " + line.substring(5) + "\r\n");
            } else {
                // Print the raw line received by the bot.
                System.out.println(line);
            }
        }
    }
    
    public void send(String message) throws Exception {
        System.out.println(message.isEmpty());
        if (!message.isEmpty()) {
            System.out.println( "Message: > PRIVMSG " + channel + " :" + message + "\r\n");
            sendRawLine("PRIVMSG " + channel + " :" + message + "\r\n");            
        }
    }
    
    public void leave() throws Exception {
        sendRawLine("PART " + channel + "\r\n");
    }
}

alright, this code there should actually work fine. I mean you should still remove public attributes, but it should work. Can you probably clarify your Problem again? When exactly do you lose the connection?

it was just a short test script, that it the reason for the public attributes :wink:

Iā€™ll hope i understand ā€œprobably clairifyā€ right as ā€œexplain it againā€.
The mailproblem is, that the script are get into the twitch chat und get the messages of the normal ā€œpublicā€ chat, the whisper AND all notifications (user ban/timeout/purge, subscription, followā€¦).
All messages the script get but after a view minutes they get no public messages anymore (only whisper) and after a few minutes later, no whisper too. The script is still running (iā€™ll try it with a terminal output each 10 mins and this running all the time).

It has no spezial time, messages or elseā€¦ sometimes the script run hours and sometimes only es few minutesā€¦
At the biginning i thought it was because noone write into the chat but sometimes it happand if the chat is writing each secondā€¦
It isnā€™t at different times and on defferent computers and internet-connections (other router and other hoster).
Iā€™ll try it with different accounts too but the problem is still there.

i dont have any idea >.<
i think this sounds like an excuse but could it be possible a problem on a part of twitch?

Sounds super weird tho. I have a few things running too related with chat and they never had an issue like that, so i still assume its something with your script. Can you actually send messages? For me this sounds either as an authentication or a timeout problem. Make sure you are correctly responding to Pings.

while i get messages i can send messages into the chat. on each ping i answer with a pong and that works fineā€¦but iā€™ll look that sometimes iā€™ll dont get any ping but i cant send i pong to the server without a pingā€¦ or?