├── .project ├── readme ├── irc_gateway.js └── irc_client.html /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | gruppe_beta 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /readme: -------------------------------------------------------------------------------- 1 | A simple IRC-Webclient based on node.js and socket.io. Thus it uses websockets 2 | for the communication between node.js server and the browser. 3 | 4 | Most of the functionality is implemented to be run at the client side. This 5 | enshures that user can only break their own client if they try to modify them. 6 | Furthermore this means less stress for the server. 7 | 8 | Start with: 9 | node irc_gateway.js [port] 10 | -------------------------------------------------------------------------------- /irc_gateway.js: -------------------------------------------------------------------------------- 1 | var net = require("net"); 2 | var app = require('http').createServer(handler) 3 | , io = require('socket.io').listen(app) 4 | , fs = require('fs') 5 | 6 | 7 | var port = process.argv.length == 3 ? Number( process.argv[2] ) : 8080; 8 | 9 | /** 10 | * \brief Webserver to deliver client files. 11 | * @param req the request 12 | * @param res the response 13 | */ 14 | app.listen( port ); 15 | function handler (req, res) { 16 | fs.readFile(__dirname + '/irc_client.html', 17 | function (err, data) { 18 | if (err) { 19 | res.writeHead(500); 20 | return res.end('Error loading index.html'); 21 | } 22 | res.setHeader( 'Content-Type', 'text/html;charset=UTF-8' ); 23 | res.writeHead(200); 24 | res.end(data); 25 | }); 26 | } 27 | 28 | 29 | /** 30 | * \brief This function handles the connection to the clients. 31 | */ 32 | io.sockets.on('connection', function (webSocket) { 33 | var tcpStream = new net.Stream; 34 | tcpStream.setTimeout(0); 35 | tcpStream.setEncoding("ascii"); 36 | webSocket.on('message', function (message) { 37 | try 38 | { 39 | if(message.split(' ')[0] == 'CONNECT') 40 | { 41 | //connect to the given IRC server via TCP 42 | var host = message.split(' ')[1].split(':')[0]; 43 | var port = message.split(' ')[1].split(':')[1]; 44 | console.log( 'connecting to '+host+':'+port+'…' ); 45 | tcpStream.destroy(); 46 | tcpStream.connect( port, host ); 47 | } 48 | else 49 | { 50 | //forward message to the remote server via TCP 51 | tcpStream.write(message); 52 | } 53 | } 54 | catch (e) 55 | { 56 | webSocket.send(e); 57 | } 58 | }); 59 | /** 60 | * \brief this function closes the connection to the IRC server when the connection to the client is closed. 61 | */ 62 | webSocket.on('disconnect', function () { 63 | tcpStream.end(); 64 | }); 65 | 66 | /** 67 | * \brief This function forwards error messages to the client 68 | */ 69 | tcpStream.addListener("error", function (error){ 70 | //forward error message to websocket 71 | webSocket.send(error+"\r\n"); 72 | }); 73 | /** 74 | * \brief This function handles the data received from the IRC server. 75 | **/ 76 | tcpStream.addListener("data", function (data) { 77 | //forward data to websocket 78 | webSocket.send(data); 79 | }); 80 | 81 | 82 | /** 83 | * \brief This function notifies the client when the connection to the server is closed. 84 | **/ 85 | tcpStream.addListener("close", function (){ 86 | webSocket.send("Server closed connection. You are offline. Use /connect to connect."); 87 | }); 88 | }); 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /irc_client.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JS IRC Client 5 | 6 | 7 | 8 | 9 | 37 | 258 | 259 |
260 |
261 | 262 |
263 | 264 | 265 |
266 |
267 |
268 |
269 |
270 |
271 |
    272 |
  • Welcome to IRC webclient
  • 273 |
274 |
275 |
276 |
    277 |
  • server
  • 278 |
279 |
280 |
281 |
282 |
283 |
284 | 285 | 286 |
287 |
288 |
289 | 290 | 291 | --------------------------------------------------------------------------------