连接到套接字和输出服务器协议后程序冻结(Twtich IRC #JAVA)

时间:2016-11-07 17:40:52

标签: java sockets irc twitch

我遇到这个问题,每当我按下GUI上的连接按钮时,它会输出服务器消息,之后我的GUI就会冻结。我真的不知道问题出在哪里。

ConnectButton(ActionPerformed)

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        try {           
            Connect();   
            ReadMessages();
        } catch (IOException ex) {
            System.out.println("Something went horribly wrong! (Connect)\n");
        }

Connect Method Connect()

public void Connect() throws IOException{

this.BotName = jTextField1.getText();
this.AuthKey = jTextField2.getText();
this.Channelname = jTextField3.getText();

this.jTextArea1.append("Starting Connection To: " + Server + "\n");

    try{

    out.write("PASS " + this.AuthKey + "\r\n");
    out.write("NICK " + this.BotName + "\r\n");
    out.write("USER " + this.BotName + " 8 " + this.BotName + "\r\n");
    out.write("CAP REQ :twitch.tv/membership\r\n");
    out.write("CAP REQ :twitch.tv/commands\r\n");
    out.write("JOIN #" + this.Channelname + "\r\n");
    out.flush();

    if(socket.isConnected()){
        this.jButton1.setEnabled(false);
        this.jTextArea1.append("Successfully Connected!\n");
        this.jButton3.setEnabled(true);
    }

    }catch(Exception e){
        System.out.println("Something went horribly wrong! (Connect/func)\n");
    }     

}

ReadMessages方法ReadMessages()

public void ReadMessages() throws IOException{

            String line;
            while ((line = in.readLine()) != null) {
            System.out.println(line); 
            } 

            }  

冻结之前的控制台输出

:tmi.twitch.tv 001 botomig :Welcome, GLHF!
:tmi.twitch.tv 002 botomig :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 botomig :This server is rather new
:tmi.twitch.tv 004 botomig :-
:tmi.twitch.tv 375 botomig :-
:tmi.twitch.tv 372 botomig :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 376 botomig :>
:tmi.twitch.tv CAP * ACK :twitch.tv/membership
:tmi.twitch.tv CAP * ACK :twitch.tv/commands
:botomig!botomig@botomig.tmi.twitch.tv JOIN #tomig_
:botomig.tmi.twitch.tv 353 botomig = #tomig_ :botomig
:botomig.tmi.twitch.tv 366 botomig #tomig_ :End of /NAMES list
:tmi.twitch.tv USERSTATE #tomig_
:tmi.twitch.tv ROOMSTATE #tomig_
:nightbot!nightbot@nightbot.tmi.twitch.tv JOIN #tomig_
:jtv MODE #tomig_ +o nightbot

0 个答案:

没有答案