Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sure, it's easily possible! It's a pretty basic TCP protocol.</p> <p>GCC is just a compiler (and a linker). There is no direct connection between GCC and IRC.<br> To connect to the server and communicate with it, you just need <code>sys/socket.h</code>; I won't go in details, there's a lot of examples and tutorials about server-client linux C/C++ programs.</p> <p>Let's see and try to understand the IRC protocol using <code>telnet</code> (a command-line telnet client program).</p> <p>First, we need to establish connection to the server (let's say it's <code>irc.freenode.net</code> with the default port, <code>6667</code>):</p> <pre><code>$ telnet irc.freenode.net 6667 </code></pre> <p>The server replies with:</p> <pre><code>:sturgeon.freenode.net NOTICE * :*** Looking up your hostname... :sturgeon.freenode.net NOTICE * :*** Checking Ident :sturgeon.freenode.net NOTICE * :*** No Ident response :sturgeon.freenode.net NOTICE * :*** Couldn't look up your hostname </code></pre> <p>Now we need to send three things: <code>PASS</code>, <code>USER</code> and <code>NICK</code>.</p> <p><code>PASS</code> is a command that sends a connection password. On the public servers (which doesn't have any password) you may send <code>PASS none</code>. </p> <p><code>USER</code> is a command that tells the server your username, host name and real name. Like, when you <code>whois</code> someone, you see <code>username@1.2.3.4</code> and his "Real Name". That data the client sends just after establishing the connection.</p> <p><code>NICK</code> is a command to set your nickname. Of course the server should know your nickname, so you should sent it right after connection too! </p> <p>So, we established a connection. Now you have to send those commands, just type them into telnet:</p> <pre><code>PASS none NICK sorandom29 USER blah blah blah blah </code></pre> <p>Woohoo, we've got an answer!</p> <pre><code>:lindbohm.freenode.net 001 sorandom29 :Welcome to the freenode Internet Relay Chat Network sorandom29 </code></pre> <p>Another important thing - there are <code>PING</code> and <code>PONG</code> commands, so if you don't answer the server with a <code>PONG</code> for a long time, you get disconnected.</p> <p>Let's see how it's done. We get a PING request:</p> <pre><code>PING :lindbohm.freenode.net </code></pre> <p>And then just answer it with the same parameters:</p> <pre><code>PONG :lindbohm.freenode.net </code></pre> <p>Then, you might wonder how could you join a channel.</p> <pre><code>JOIN #linux </code></pre> <p>Yeah, that's it.</p> <pre><code>:lindbohm.freenode.net 470 sorandom29 #linux ##linux :Forwarding to another channel :sorandom29!~blah JOIN ##linux :lindbohm.freenode.net 332 sorandom29 ##linux :Welcome to ##Linux! Freenode's general Linux support/discussion channel. </code></pre> <p>Another command is <code>PRIVMSG</code>, it sends an actual message to the channel or somebody else:</p> <pre><code>PRIVMSG #linux :hello guys! i'm using telnet to connect to irc and that's such a stupid idea, i have to respond to PINGs manually! </code></pre> <p>So everybody on <code>#linux</code> will see that:</p> <pre><code>&lt;sorandom29&gt; hello guys! i'm using telnet to connect to irc and that's such a stupid idea, i have to respond to PINGs manually! </code></pre> <p>Note that a <code>:</code> is a prefix before the message itself.</p> <p>I guess that's enough to get into IRC. The whole lot of other stuff you can try yourself just by reading about <a href="http://tools.ietf.org/html/rfc1459" rel="noreferrer">IRC protocol</a> itself, trying things with <code>telnet</code> or <code>nc</code> and then getting into coding a program using the basic sockets.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload