|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.lang.Thread
org.schwering.irc.lib.IRCConnection
public class IRCConnection
Creates a new connection to an IRC server. It's the main class of the IRClib, the point everything starts.
The following sample code tries to establish an IRC connection to an IRC server:
/*
* The following code of a class which imports org.schwering.irc.lib.*
* prepares an IRC connection and then tries to establish the connection.
* The server is "irc.somenetwork.com", the default portrange (6667 and
* 6669) is set, no password is used (null). The nickname is "Foo" and
* the realname is "Mr. Foobar". The username "foobar".
* Because of setDaemon(true), the JVM exits even if this thread is
* running.
* An instance of the class MyListener which must implement
* IRCActionListener is added as only event-listener for the connection.
* The connection is told to parse out mIRC color codes and to enable
* automatic PING? PONG! replies.
*/
IRCConnection conn = new IRCConnection(
"irc.somenetwork.com",
6667,
6669,
null,
"Foo",
"Mr. Foobar",
"foo@bar.com"
);
conn.addIRCEventListener(new MyListener());
conn.setDaemon(true);
conn.setColors(false);
conn.setPong(true);
try {
conn.connect(); // Try to connect!!! Don't forget this!!!
} catch (IOException ioexc) {
ioexc.printStackTrace();
}
The serverpassword isn't needed in most cases. You can give
null or "" instead as done in this example.
IRCEventListener,
IRCParser,
IRCUtil,
SSLIRCConnection| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
protected String |
encoding
The String contains the name of the character encoding used
to talk to the server. |
protected String |
host
The host of the IRC server. |
protected byte |
level
This is like a UNIX-runlevel. |
protected int[] |
ports
The int[] contains all ports to which we are going to try to
connect. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
IRCConnection(String host,
int[] ports,
String pass,
String nick,
String username,
String realname)
Creates a new IRC connection. |
|
IRCConnection(String host,
int portMin,
int portMax,
String pass,
String nick,
String username,
String realname)
Creates a new IRC connection. |
|
| Method Summary | |
|---|---|
void |
addIRCEventListener(IRCEventListener l)
Adds a new IRCEventListener which listens
for actions coming from the IRC server. |
void |
close()
Close down the connection brutally. |
void |
connect()
Establish a connection to the server. |
void |
doAway()
Removes away message. |
void |
doAway(String msg)
Sets away message. |
void |
doInvite(String nick,
String chan)
Invites a user to a channel. |
void |
doIson(String nick)
Checks if one or more nicks are used on the server. |
void |
doJoin(String chan)
Joins a channel without a key. |
void |
doJoin(String chan,
String key)
Joins a channel with a key. |
void |
doKick(String chan,
String nick)
Kicks a user from a channel. |
void |
doKick(String chan,
String nick,
String msg)
Kicks a user from a channel with a comment. |
void |
doList()
Lists all channels with their topic and status. |
void |
doList(String chan)
Lists channel(s) with their topic and status. |
void |
doMode(String chan)
Requests a Reply 324 for the modes of a given channel. |
void |
doMode(String target,
String mode)
Sends a mode to the server. |
void |
doNames()
Lists all visible users. |
void |
doNames(String chan)
Lists all visible users of (a) channel(s). |
void |
doNick(String nick)
Changes the nickname. |
void |
doNotice(String target,
String msg)
Notices a message to a person or a channel. |
void |
doPart(String chan)
Parts from a given channel. |
void |
doPart(String chan,
String msg)
Parts from a given channel with a given parg-msg. |
void |
doPong(String ping)
Quits from the IRC server with a quit-msg. |
void |
doPrivmsg(String target,
String msg)
Sends a message to a person or a channel. |
void |
doQuit()
Quits from the IRC server. |
void |
doQuit(String msg)
Quits from the IRC server with a quit-msg. |
void |
doTopic(String chan)
Requests the topic of a chan. |
void |
doTopic(String chan,
String topic)
Changes the topic of a chan. |
void |
doUserhost(String nick)
Requires host-information about up to 5 users which must be listed and divided by spaces. |
void |
doWho(String criteric)
Requests information about users matching the given criteric, for example a channel they are on. |
void |
doWhois(String nick)
Requires information about an existing user. |
void |
doWhowas(String nick)
Requires host-information about a user, who is not connected anymore. |
boolean |
getColors()
Indicates whether colors are stripped out or not. |
String |
getEncoding()
Returns the encoding of the socket. |
String |
getHost()
Returns the server of this instance. |
String |
getNick()
Returns the nickname of this instance. |
String |
getPassword()
Returns the password of this instance. |
boolean |
getPong()
Indicates whether automatic PING? PONG! is enabled or not. |
int |
getPort()
Returns the port to which the IRCConnection connected, or
0 if the connection failed or wasn't tried yet. |
int[] |
getPorts()
Returns all ports to which the IRCConnection is going to try
or has tried to connect to. |
String |
getRealname()
Returns the realname of this instance. |
int |
getTimeout()
Returns the timeout of the socket. |
String |
getUsername()
Returns the username of this instance. |
boolean |
isConnected()
Tells whether there's a connection to the IRC network or not. |
protected void |
prepare(Socket s)
Invoked by the connect method, this method prepares the
connection. |
boolean |
removeIRCEventListener(IRCEventListener l)
Removes the first occurence of the given IRCEventListener from the listener-vector. |
void |
run()
The Thread is started by the connect method. |
void |
send(String line)
Sends a String to the server. |
void |
setColors(boolean colors)
Enables or disables the mIRC colorcodes. |
void |
setEncoding(String encoding)
Changes the character encoding used to talk to the server. |
void |
setPong(boolean pong)
Enables or disables the automatic PING? PONG! support. |
void |
setTimeout(int millis)
Sets the connection's timeout in milliseconds. |
String |
toString()
Generates a String with some information about the instance of
IRCConnection. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected byte level
IRCConnection object. 0 means that the object
has not yet been connected, 1 means that it's connected but
not registered, 2 means that it's connected and registered
but still waiting to receive the nickname the first time, 3
means that it's connected and registered, and -1 means that
it was connected but is disconnected.
Therefore the defaultvalue is 0.
protected String host
protected int[] ports
int[] contains all ports to which we are going to try to
connect. This can be a portrange from port 6667 to 6669, for example.
protected String encoding
String contains the name of the character encoding used
to talk to the server. This can be ISO-8859-1 or UTF-8 for example. The
default is ISO-8859-1.
| Constructor Detail |
|---|
public IRCConnection(String host,
int[] ports,
String pass,
String nick,
String username,
String realname)
int[]. Thus, also ports like 1024, 2048, 6667 and
6669 can be selected.connect method. Before invoking it, you should
set the IRCEventListener and other settings."" or null for the password
argument in the constructor.
host - The hostname of the server we want to connect to.ports - The portrange to which we want to connect.pass - The password of the IRC server. If your server isn't
secured by a password (that's normal), use
null or "".nick - The nickname for the connection. Is used to register the
connection.username - The username. Is used to register the connection.realname - The realname. Is used to register the connection.
IllegalArgumentException - If the host or
ports is null or
ports' length is
0.connect()
public IRCConnection(String host,
int portMin,
int portMax,
String pass,
String nick,
String username,
String realname)
ints. Thus, only a portrange from port x to
port y like from port 6667 to 6669 can be selected.connect method. Before invoking it, you should
set the IRCEventListener and other settings."" or null for the password
argument in the constructor.
host - The hostname of the server we want to connect to.portMin - The beginning of the port range we are going to connect
to.portMax - The ending of the port range we are going to connect to.pass - The password of the IRC server. If your server isn't
secured by a password (that's normal), use
null or "".nick - The nickname for the connection. Is used to register the
connection.username - The username. Is used to register the connection.realname - The realname. Is used to register the connection.
IllegalArgumentException - If the host is
null.connect()| Method Detail |
|---|
public void connect()
throws IOException
IOException.connect only one time.
IOException - If an I/O error occurs.
SocketException - If the connect method was already
invoked.isConnected(),
doQuit(),
doQuit(String),
close()
protected void prepare(Socket s)
throws IOException
connect method, this method prepares the
connection. register() and starts the receiving of lines from the server
by starting the thread with the start method.connect method.
s - The socket which is used for the connection.
IOException - If an I/O error occurs.connect(),
run()public void run()
Thread is started by the connect method.
It's task is to receive strings from the IRC server and hand them over
to the get method.
run in interface Runnablerun in class Threadpublic void send(String line)
do* methods (like doJoin). A carriage
return line feed (\r\n) is appended automatically.
line - The line which should be send to the server without the
trailing carriage return line feed (\r\n).public void close()
QUIT. You should
always use the doQuit methods or send("QUIT")
instead of this method. QUIT command.
connect(),
doQuit(),
doQuit(String)public void addIRCEventListener(IRCEventListener l)
IRCEventListener which listens
for actions coming from the IRC server.
l - An instance of the
IRCEventListener interface.
IllegalArgumentException - If listener is
null.public boolean removeIRCEventListener(IRCEventListener l)
IRCEventListener from the listener-vector.
l - An instance of the
IRCEventListener interface.
true if the listener was successfully removed;
false if it was not found.public void setColors(boolean colors)
colors - true to enable, false to disable
colors.public void setPong(boolean pong)
pong - true to enable automatic PONG
reply, false makes the class fire
onPing events.public void setEncoding(String encoding)
connect()
method.
encoding - public void setTimeout(int millis)
1000 * 60 15 millis which are 15 minutes.
public boolean isConnected()
connect wasn't called yet, it returns false.
true if it's connected.connect(),
doQuit(),
doQuit(String),
close()public String getNick()
public String getRealname()
public String getUsername()
public String getHost()
public String getPassword()
null is returned.
null is
returned.public int[] getPorts()
IRCConnection is going to try
or has tried to connect to.
int[] array.public int getPort()
IRCConnection connected, or
0 if the connection failed or wasn't tried yet.
IRCConnection, or
0 if the connection failed or wasn't tried yet.public boolean getColors()
true if colors are disabled.public boolean getPong()
true if PING? PONG! is done automatically.public String getEncoding()
public int getTimeout()
-1 is returned.
public String toString()
String with some information about the instance of
IRCConnection.
Its format is:
classname[host,portMin,portMax,username,nick,realname,pass,connected]
.
toString in class ThreadString with information about the instance.public void doAway()
public void doAway(String msg)
msg - The away message.
public void doInvite(String nick,
String chan)
nick - The nickname of the user who should be invited.chan - The channel the user should be invited to.public void doIson(String nick)
nick - The nickname of the user we search for.public void doJoin(String chan)
chan - The channel which is to join.
public void doJoin(String chan,
String key)
chan - The channel which is to join.key - The key of the channel.
public void doKick(String chan,
String nick)
chan - The channel somebody should be kicked from.nick - The nickname of the user who should be kicked.
public void doKick(String chan,
String nick,
String msg)
chan - The channel somebody should be kicked from.nick - The nickname of the user who should be kicked.msg - The optional kickmessage.public void doList()
public void doList(String chan)
chan - The channel the LIST refers to.public void doNames()
public void doNames(String chan)
chan - The channel the NAMES command is refering to.
public void doPrivmsg(String target,
String msg)
target - The nickname or channel the message should be sent to.msg - The message which should be transmitted.public void doMode(String chan)
chan - The channel the MODE request is refering to.
public void doMode(String target,
String mode)
String mode must contain the operators (+/-), the modes
(o/v/i/k/l/p/s/w) and the possibly values (nicks/banmask/limit/key).
target - The nickname or channel of the user whose modes will be
changed.mode - The new modes.public void doNick(String nick)
nick - The new nickname.
public void doNotice(String target,
String msg)
target - The nickname or channel (group) the message should be
sent to.msg - The message which should be transmitted.public void doPart(String chan)
chan - The channel you want to part from.
public void doPart(String chan,
String msg)
chan - The channel you want to part from.msg - The optional partmessage.public void doPong(String ping)
ping - The ping which was received in onPing. It's a
String, because sometimes on some networks
the server-hostname (for example splatterworld.quakenet.org) is
given as parameter which would throw an Exception if we
gave the ping as long.public void doQuit()
disconnect-method which does the work actually.
isConnected(),
connect(),
doQuit(String),
close()public void doQuit(String msg)
disconnect-method which does the work actually.
msg - The optional quitmessage.isConnected(),
connect(),
doQuit(),
close()public void doTopic(String chan)
chan - The channel which topic should be requested.
public void doTopic(String chan,
String topic)
chan - The channel which topic is changed.topic - The new topic.public void doWho(String criteric)
criteric - The criterics of the WHO query.public void doWhois(String nick)
nick - The nickname of the user the query is refering to.public void doWhowas(String nick)
nick - The nickname of the user the query is refering to.public void doUserhost(String nick)
nick - The nickname of the user the query is refering to.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||