Skip to content

Commit a4c09a9

Browse files
author
Ilker Guller
committed
Added files
0 parents  commit a4c09a9

File tree

691 files changed

+81145
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

691 files changed

+81145
-0
lines changed

Readme.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
3+
Chat Tutorial with Node.js, Socket.io and Express
4+
5+
////////////////////////////////////////////////////////////////////////////////
6+
7+
8+
This is sample project to show how to create chat system with Node.js, Socket.io and Express.
9+
10+
Used Libraries:
11+
12+
// Node.js : http://nodejs.org
13+
// Socket.io : http://socket.io
14+
// Express : http://expressjs.com
15+
// Jquery : http://www.jquery.com
16+
17+
Tutorial Link is in my blog.
18+
19+
// Developed by Ilker Guller http://developerarea.blogspot.com/

app.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Bu kısım otomatik Express tarafından yaratıldı.
3+
* Ilker Guller
4+
* http://developerarea.blogspot.com
5+
*/
6+
7+
/**
8+
* Module dependencies.
9+
*/
10+
11+
var express = require('express')
12+
, routes = require('./routes');
13+
14+
var app = module.exports = express.createServer();
15+
16+
// Configuration
17+
18+
app.configure(function(){
19+
app.set('views', __dirname + '/views');
20+
app.set('view engine', 'jade');
21+
app.use(express.bodyParser());
22+
app.use(express.methodOverride());
23+
app.use(app.router);
24+
app.use(express.static(__dirname + '/public'));
25+
});
26+
27+
app.configure('development', function(){
28+
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
29+
});
30+
31+
app.configure('production', function(){
32+
app.use(express.errorHandler());
33+
});
34+
35+
// Routes
36+
app.get('/', routes.index);
37+
38+
// Bu Kısmı ben ekledim.
39+
app.get('/chatPage', routes.chatPage);
40+
41+
app.listen(3000);
42+
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
43+
44+
/**
45+
* Yukarıdaki kısım otomatik Express tarafından yaratıldı.
46+
* Ilker Guller
47+
* http://developerarea.blogspot.com
48+
*/
49+
50+
// Socket bağlantısı kurulur
51+
var io = require('socket.io').listen(app);
52+
53+
// Kullanıcı Listesinin tutulacağı Object
54+
var kullanicilar = {};
55+
56+
// Bağlantı kurulduğunda çalışacak kısım
57+
io.sockets.on('connection', function(socket){
58+
// Kullanıcı Ekleme Fonksiyonu
59+
socket.on("kullaniciEkle", function(kullaniciadi){
60+
// Kullanıcı session'nda bilgileri saklıyoruz
61+
socket.kullaniciAdi = kullaniciadi;
62+
socket.userId = kullanicilar.length;
63+
64+
// Array'e kullanıcı bilgilerini ekliyoruz
65+
kullanicilar[kullaniciadi] = {
66+
userName : kullaniciadi,
67+
userId : kullanicilar.length
68+
};
69+
70+
// Bağlanan kullanıcıya hoşgeldin mesajı yolluyoruz
71+
socket.emit("mesajGonder", "Sistem", "Hoşgeldiniz.");
72+
73+
// Bütün kullanıcılara yeni kullanıcı bağlandı mesajı yolluyoruz
74+
socket.broadcast.emit("mesajGonder", "Sistem", kullaniciadi + " muhabbete bağlandı.");
75+
76+
// Bağlı kullanıcılarda Kullanıcı listesini yeniliyoruz
77+
io.sockets.emit("kullanicilariYenile", kullanicilar);
78+
});
79+
80+
// Bağlantı kesildiği takdirde çalışacak fonksiyon
81+
socket.on("disconnect", function(){
82+
// Kullanıcıyı listeden siliyoruz
83+
delete kullanicilar[socket.kullaniciAdi];
84+
85+
// Bağlı kullanıcılarda Kullanıcı listesini yeniliyoruz
86+
io.sockets.emit("kullanicilariYenile", kullanicilar);
87+
88+
// Bağlı kullanıcılara kullanıcı çıktı mesajı yolluyoruz
89+
socket.broadcast.emit("mesajGonder", "Sistem", socket.kullaniciAdi + " muhabbetten ayrıldı :(");
90+
});
91+
92+
// Client tarafından mesaj yollama fonksiyonu
93+
socket.on("mesajYolla", function(data){
94+
// Bağlı kullanıcılara kullanıcıdan gelen mesajı yolluyoruz
95+
io.sockets.emit("mesajGonder", socket.kullaniciAdi, data);
96+
});
97+
});

node_modules/.bin/express

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/express.cmd

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/jade

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/jade.cmd

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/express/.npmignore

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)