Question

I'm programming a custom IRC client in java, and I have the recieving messages in chat fine, but what I can't figure out is how to send chat messages. I looked at IRCHelp.org but I didn't really understand the section about "Message format in ‘pseudo’ BNF, " which I believe is the section I might be looking for.

  1. Is this the section I'm looking for?

  2. If not, what section should I look at?

Was it helpful?

Solution 3

I think your best option might be to use an IRC library. The IRC protocol is fairly simple but large at the same time, to write a complete library would actually be a fair bit of work. On the other hand it's easy to write it yourself since IRC is a text based protocol.

Why don't you take a look at one of these:

  • JerkLib - Uses NIO and is event driven
  • Sorcix' sIRC - Very compact library, uses listeners
  • PircBot - Rather for writing irc bots
  • IRClib - Neatly organised compact irc library that has support for SSL

If you're certain you want to write the implementation yourself you can have a look at this.

OTHER TIPS

Look at the RFC 1459.
It also uses pseudo-BNF, but it is actually easy to understand.

Example:

4.4.1 Private messages

Command: PRIVMSG
Parameters: <receiver>{,<receiver>} <text to be sent>

PRIVMSG is used to send private messages between users. is the nickname of the receiver of the message. can also be a list of names or channels separated with commas.

The parameter may also me a host mask (#mask) or server mask ($mask). In both cases the server will only send the PRIVMSG to those who have a server or host matching the mask. The mask must have at least 1 (one) "." in it and no wildcards following the last ".". This requirement exists to prevent people sending messages to "#" or "$", which would broadcast to all users; from experience, this is abused more than used responsibly and properly. Wildcards are the '*' and '?' characters. This extension to the PRIVMSG command is only available to Operators.

Numeric Replies:

      ERR_NORECIPIENT                 ERR_NOTEXTTOSEND
      ERR_CANNOTSENDTOCHAN            ERR_NOTOPLEVEL
      ERR_WILDTOPLEVEL                ERR_TOOMANYTARGETS
      ERR_NOSUCHNICK
      RPL_AWAY

Examples:

:Angel PRIVMSG Wiz :Hello are you receiving this message ?

;Message from Angel to Wiz.

PRIVMSG Angel :yes I'm receiving it !receiving it !

Message to Angel.

PRIVMSG jto@tolsun.oulu.fi :Hello !

Message to a client on server

Note that implementing the IRC protocol can be hard:

  • You either have to track all user in the channel and change the client-side view of the users on a JOIN, PART, QUIT KICK and NICK (and parsing the NAMES reply on your join, or ask the server everytime you need a userlist for the NAMES in that channel. For a client (which displays the userlist) you have to track it.
  • IRC Colors: Some people say that it was the worst idea ever implemented in a client (mIRC), but they exist and most clients support them. If you don't, strip them (They start with \x02 and \x03)
  • CTCP Supporting CTCPs is important:
    • Some servers ask for a VERSION reply on connect, some servers even disallow clients without one.
    • ACTION ctcps are common and used for the /me command.
    • DCC ctcps are common and used for file transfers, establishing direct chat connections, and sending encrypted messages.
  • Provide a way for the user to inject abitiary commands. Most clients support the use of /raw or /quote, some even send every unknown command to the server.
  • Provide the common aliases for /kick, /op...

I can't tell whether you're asking for IRC RFC/Protocol help or actual code since you hanve't supplied any of your current code. When you establish a read stream to a server, output everything to your console. There's a lot to handle, but doing so will make it very clear as to how the protocol works. As for some code along with the protocol:

BufferedWriter writer = new BufferedWriter(new InputStreamReader(socket.getInputStream());

writer.writeLine("PRIVMSG <destination> :<message>\r\n");
writer.flush();

Obviously the above requires a try-catch.

Receiving a private message from a user will be in this format:

:<sender-nickname>!<sender-ident>@<sender-server> PRIVMSG <your-nickname> :<the-senders-message>

Example:

:StephenHero!SHPC@google.com PRIVMSG Mast3rPlan :Hello Master Plan!

Many IRC server responses commands follow this syntax, [in other words]:

:SENDER COMMAND RECIPIENT :MESSAGE
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top