Giter Site home page Giter Site logo

socket.io-client's Introduction

socket.io-client

A socket.io-client implementation for ESP8266 and Arduino.

Index

Install

๐Ÿ’ก This library uses lstdc++

To compile you have to add a reference to the linker. To do so edit platform.txt in $ARDUINO_IDE/hardware/esp8266com/esp8266 and add '-lstdc++' to the line

compiler.c.elf.libs= ...

๐Ÿ’ก Note: See ESP8266 for Arduino IDE (xtensa-lx106-elf-gcc) and std::map linking error.

Add library

Best thing is to use the Arduino Library Manager.

  1. Go to Sketch > Include Library > Manage Libraries.
  2. Install WebSockets by Markus Sattler
  3. Install SocketIoClient
  4. Select Sketch > Include Library > SocketIoClient

Functions

  1. SocketIoClient::begin()
  2. SocketIoClient::beginSSL()
  3. SocketIoClient::disconnect()
  4. SocketIoClient::emit()
  5. SocketIoClient::loop()
  6. SocketIoClient::on()
  7. SocketIoClient::remove()
  8. SocketIoClient::setAuthorization()

SocketIoClient::begin(host[, port, path])

Open connection to socket.io server.

Parameter

host url to socket.io server port port to connect on. Defaults to 80 or 443 (SSL) path path to connect to on server. Defaults to "/socket.io/?transport=websocket"

Example
socket.begin("my.socket-io.server", 443, "/socket.io/?transport=websocket");

SocketIoClient::beginSSL(host[, port, path, fingerprint])

Open SSL connection to socket.io server.

Parameter

host url to socket.io server port port to connect on. Defaults to 80 or 443 (SSL) path path to connect to on server. Defaults to "/socket.io/?transport=websocket" fingerprint the SSL fingerprint. Defaults to ""

Example
socket.beginSSL("my.socket-io.server", 443, "/socket.io/?transport=websocket", "26 96 1C 2A 51 07 FD 15 80 96 93 AE F7 32 CE B9 0D 01 55 C4");

SocketIoClient::disconnect()

Disconnect from the server.

Example
socket.disconnect();

SocketIoClient::emit(event, payload)

Emits an event to the server.

Parameter

event name of the event to be emitted payload string of the payload to be sent with the event. Plain strings and object property names should be encapsulated in quotes.

Example
socket.emit("plainString", "\"this is a plain string\"");
socket.emit("jsonObject", "{\"foo\":\"bar\"}");

SocketIoClient::loop()

Processes the websocket. Should be called in Arduino main loop.

SocketIoClient::on(event, callback)

Binds a function to an event.

Parameter

event name of the event to bind to callback callback function to call when the event is triggered Function signature must be

void (const char * payload, size_t length)
Example
void event(const char * payload, size_t length) {
	// do stuff
}
socket.on("event", event);
Supported default events:
  • connect - when user is connected to server
  • disconnect - when user is disconnected from the server

SocketIoClient::remove(event)

Removes the previously added event.

Parameter

event name of the event binded

Example
socket.remove("event");

SocketIoClient::setAuthorization(username, password)

Set HTTP Basic auth username and password.

Example
socket.setAuthorization("username", "password");

Miscellaneous

To go along with the socket.io-client implementation of socket.io the connect event is triggered upon successfully opened connection to server. To utilize simply add

socket.on("connect", handler)

Likewise, disconnect event is triggered upon terminated connection.

Example

See Example

Contribution

Based on the great work of Links2004 / arduinoWebSockets.

socket.io-client's People

Contributors

bmooij-beeliners avatar caioaletroca avatar fcouceiro avatar fzoccara avatar he0119 avatar jslay88 avatar kadah avatar race2infinity avatar sarthakz9 avatar timum-viw avatar yoav97h avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.