making client with socket.io

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 <script src="js/socket.io.js"></script>
 <script>
 // Create SocketIO instance, connect
 var socket = new io.Socket('localhost',{    port: 8000  });
 socket.connect(); 

 // Add a connect listener
 socket.on('connect',function() {
 console.log('Client has connected to the server!');

 });
 // Add a connect listener
 socket.on('message',function(data) {
 console.log('Received a message from the server!',data);
 });
 // Add a disconnect listener
 socket.on('disconnect',function() {
 console.log('The client has disconnected!');
 });

 // Sends a message to the server via sockets
 function sendMessageToServer(message) {
 socket.send(message);
 }
 var request={};
request.command='.login';
 request.password='12345';
 request.username='rahul';
 socket.send(request);
 </script>

References

https://github.com/LearnBoost/Socket.IO-node

http://socket.io/

http://davidwalsh.name/websocket

Advertisements

About rahul23134654

Hi, I am Rahul Meha , B.E. in (I.T.)
This entry was posted in Node.js. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s