Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple IRC Client in Java
import java.net.*;
import java.io.*;
import java.util.*;
class IrcSenderSimple {
static void sendString(BufferedWriter bw, String str) {
try {
bw.write(str + "\r\n");
bw.flush();
}
catch (Exception e) {
System.out.println("Exception: "+e);
}
}
public static void main(String args[]) {
try {
String server = "chat1.ustream.tv";
int port = 6667;
String nickname = "ustreamer-183999bot";
String channel = "#bot-test-ch";
String message = "hi, all";
Socket socket = new Socket(server,port);
System.out.println("*** Connected to server.");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream());
System.out.println("*** Opened OutputStreamWriter.");
BufferedWriter bwriter = new BufferedWriter(outputStreamWriter);
System.out.println("*** Opened BufferedWriter.");
sendString(bwriter,"NICK "+nickname);
sendString(bwriter,"USER chatterBot 8 * :chatterBot 0.0.1 Java IRC Bot - www.chat.org");
sendString(bwriter,"JOIN "+channel);
/*
// サーバーからの応答確認
InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream());
BufferedReader breader = new BufferedReader(inputStreamReader);
String line = null;
int tries = 1;
while ((line = breader.readLine()) != null) {
System.out.println(">>> "+line);
int firstSpace = line.indexOf(" ");
int secondSpace = line.indexOf(" ", firstSpace + 1);
if (secondSpace >= 0) {
String code = line.substring(firstSpace+1, secondSpace);
if (code.equals("004")) {
break;
}
}
}
*/
sendString(bwriter,"PRIVMSG "+channel+" :"+message);
bwriter.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
@sebepe

This comment has been minimized.

Copy link

@sebepe sebepe commented Apr 6, 2017

Hi,
It may sound dumb, but I don't know how to integrate this on a webpage ?

@corgrath

This comment has been minimized.

Copy link

@corgrath corgrath commented Apr 21, 2017

Hi,
It may sound dumb, but I don't know how to integrate this on a webpage ?

This is Java, not JavaScript.

@kaecy

This comment has been minimized.

Copy link

@kaecy kaecy commented Mar 2, 2018

This doesn't look right. I wrote my own. https://gist.github.com/kaecy/286f8ad334aec3fcb588516feb727772#file-simpleircclient-java I just don't know how I can use callbacks instead.

@t0nic

This comment has been minimized.

Copy link

@t0nic t0nic commented Oct 1, 2018

first comment made me lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.