(X)HTML, JavaScript, DHTML, XML, CSS Client scripting tehnologije, Dynamic HTML, Cascading Stylesheets, XML i standardi |
|
Alati teme | Način prikaza |
23. 04. 2012. | #1 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
Node.js, websocket, socket.IO
Node.js, websocket, socket.IO - pojasnjenje ovih tehnologija?
__________________
I'm not sexy and I know IT! |
24. 04. 2012. | #3 |
Super Moderator
Knowledge base
Datum učlanjenja: 21.03.2006
Lokacija: Kragujevac
Poruke: 1.878
Hvala: 291
1.345 "Hvala" u 355 poruka
|
|
2 članova zahvaljuje mileusna za poruku: |
24. 04. 2012. | #4 |
expert
Grand Master
Datum učlanjenja: 11.04.2010
Poruke: 998
Hvala: 141
959 "Hvala" u 153 poruka
|
Očigledno nisi nikad programirao za desktop...
|
24. 04. 2012. | #5 |
profesionalac
Professional
Datum učlanjenja: 08.11.2010
Poruke: 211
Hvala: 68
78 "Hvala" u 32 poruka
|
Dobio si extra link od mileusne al evo jos jedan kad prodjes taj sto ti je poslala
http://stackoverflow.com/questions/1...hat-is-node-js |
24. 04. 2012. | #6 |
profesionalac
Professional
Datum učlanjenja: 19.09.2011
Poruke: 241
Hvala: 15
9 "Hvala" u 8 poruka
|
primer
Evo prostog primera za razumevanje:
SOCKET SERVER: Kôd:
// Require HTTP module (to start server) and Socket.IO var http = require('http'), io = require('socket.io'); // Start the server at port 8080 var server = http.createServer(function(req, res){ // Send HTML headers and message res.writeHead(200,{ 'Content-Type': 'text/html' }); res.end('<h1>Hello Socket Lover!</h1>'); }); server.listen(8080); // Create a Socket.IO instance, passing it our server var socket = io.listen(server); // Add a connect listener socket.on('connection', function(client){ // Create periodical which ends a message to the client every 5 seconds var interval = setInterval(function() { client.send('This is a message from the server! ' + new Date().getTime()); },5000); // Success! Now listen to messages to be received client.on('message',function(event){ console.log('Received message from client!',event); }); client.on('disconnect',function(){ clearInterval(interval); console.log('Server has disconnected'); }); }); Kôd:
<!DOCTYPE html> <html> <head> <style> * { margin:0; padding:0; font-size:11px; font-family:arial; color:#444; } body { padding:20px; } #message-list { list-style-type:none; width:300px; height:300px; overflow:auto; border:1px solid #999; padding:20px; } #message-list li { border-bottom:1px solid #ccc; padding-bottom:2px; margin-bottom:5px; } code { font-family:courier; background:#eee; padding:2px 4px; } </style> <script src="http://cdn.socket.io/stable/socket.io.js"></script> <script> // Create SocketIO instance var socket = new io.Socket('localhost',{ port: 8080 }); socket.connect(); // Add a connect listener socket.on('connect',function() { log('<span style="color:green;">Client has connected to the server!</span>'); }); // Add a connect listener socket.on('message',function(data) { log('Received a message from the server: ' + data); }); // Add a disconnect listener socket.on('disconnect',function() { log('<span style="color:red;">The client has disconnected!</span>'); }); // Sends a message to the server via sockets function sendMessageToServer(message) { socket.send(message); log('<span style="color:#888">Sending "' + message + '" to the server!</span>'); } // Outputs to console and list function log(message) { var li = document.createElement('li'); li.innerHTML = message; document.getElementById('message-list').appendChild(li); } /* // Create a socket instance socket = new WebSocket('ws://localhost:8080'); // Open the socket socket.onopen = function(event) { console.log('Socket opened on client side',event); // Listen for messages socket.onmessage = function(event) { console.log('Client received a message',event); }; // Listen for socket closes socket.onclose = function(event) { console.log('Client notified socket has closed',event); }; }; */ </script> </head> <body> <p>Messages will appear below (and in the console).</p><br /> <ul id="message-list"></ul> <ul style="margin:20px 0 0 20px;"> <li>Type <code>socket.disconnect()</code> to disconnect</li> <li>Type <code>socket.connect()</code> to reconnect</li> <li>Type <code>sendMessageToServer('Your Message')</code> to send a message to the server</li> </ul> </body> </html> |
25. 04. 2012. | #7 |
Ivan Dilber
Sir Write-a-Lot
|
ajd nemoj da copy & pastujes tudj kod sa interneta, nego daj link do izvora
__________________
Leadership is the art of getting people to want to do what you know must be done. |
2 članova zahvaljuje ivanhoe za poruku: |
26. 04. 2012. | #8 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
Jel moze neko za pocetak da mi kaze kako se uopste instalira socket.io i da li je uopste moguce instalirati na shared hostingu... kako preko control panela ili ???
Ako neko zna neka napise "Korak po korak uputstvo" bice od koristi mnogima. Unapred hvala, pa za dalje cemo videti kako funcionise.
__________________
I'm not sexy and I know IT! |
26. 04. 2012. | #10 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
U dokumentaciji pise da se pokrece komandom NPM ... ...*gde,kako*??? ali kako kad uploadujem na shared hosting da instaliram socket.IO da li je pre toga potrebno imati neki drugi dodatak node???
Zanima me ovo da naucim pa koliko uspem...
__________________
I'm not sexy and I know IT! |
|
|