Socket
Socket
Sign inDemoInstall

socket.io-client

Package Overview
Dependencies
14
Maintainers
2
Versions
127
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    socket.io-client

[![Build Status](https://secure.travis-ci.org/socketio/socket.io-client.svg?branch=master)](http://travis-ci.org/socketio/socket.io-client) [![Dependency Status](https://david-dm.org/socketio/socket.io-client.svg)](https://david-dm.org/socketio/socket.io-


Version published
Weekly downloads
4.5M
increased by1.25%
Maintainers
2
Install size
2.08 MB
Created
Weekly downloads
 

Package description

What is socket.io-client?

The socket.io-client npm package is a client-side library that enables real-time, bidirectional and event-based communication between web clients and servers. It works on every platform, browser or device, focusing equally on reliability and speed.

What are socket.io-client's main functionalities?

Connecting to a server

This code sample demonstrates how to connect to a Socket.IO server running on localhost at port 3000.

const io = require('socket.io-client');
const socket = io('http://localhost:3000');

Emitting events

This code sample shows how to emit an event to the server with an event name and associated data.

socket.emit('event_name', { some: 'data' });

Listening for events

This code sample illustrates how to listen for events emitted by the server and handle them with a callback function.

socket.on('event_name', function(data) {
  console.log(data);
});

Disconnecting from the server

This code sample shows how to handle a disconnection event when the client gets disconnected from the server.

socket.on('disconnect', function() {
  console.log('Disconnected from server');
});

Other packages similar to socket.io-client

Changelog

Source

2.2.0 (2018-11-29)

Bug fixes

  • remove any reference to the global variable (related: https://github.com/socketio/socket.io-client/issues/1166)

Readme

Source

socket.io-client

Build Status Dependency Status devDependency Status NPM version Downloads

Sauce Test Status

How to use

A standalone build of socket.io-client is exposed automatically by the socket.io server as /socket.io/socket.io.js. Alternatively you can serve the file socket.io.js found in the dist folder.

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://localhost');
  socket.on('connect', function(){});
  socket.on('event', function(data){});
  socket.on('disconnect', function(){});
</script>
// with ES6 import
import io from 'socket.io-client';

const socket = io('http://localhost');

A slim build (without JSON3, a JSON polyfill for IE6/IE7, and debug) is also available: socket.io.slim.js.

Socket.IO is compatible with browserify and webpack (see example there).

Node.JS (server-side usage)

Add socket.io-client to your package.json and then:

var socket = require('socket.io-client')('http://localhost');
socket.on('connect', function(){});
socket.on('event', function(data){});
socket.on('disconnect', function(){});

API

See API

License

MIT

Keywords

FAQs

Last updated on 28 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc