GithubHelp home page GithubHelp logo

hhy5277 / java-websocket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tootallnate/java-websocket

0.0 1.0 0.0 3.46 MB

A barebones WebSocket client and server implementation written in 100% Java.

Home Page: http://tootallnate.github.io/Java-WebSocket

License: MIT License

HTML 46.74% Java 53.16% Gherkin 0.10%

java-websocket's Introduction

Java WebSockets

Build Status Javadocs Maven Central Sonatype Nexus (Snapshots)

This repository contains a barebones WebSocket server and client implementation written in 100% Java. The underlying classes are implemented java.nio, which allows for a non-blocking event-driven model (similar to the WebSocket API for web browsers).

Implemented WebSocket protocol versions are:

Here some more details about protocol versions/drafts.

Build

You can build using Maven, Gradle or Leiningen but there is nothing against just putting the source path src/main/java on your applications buildpath.

Maven

To use maven add this dependency to your pom.xml:

<dependency>
  <groupId>org.java-websocket</groupId>
  <artifactId>Java-WebSocket</artifactId>
  <version>1.3.9</version>
</dependency>

Gradle

To use Gradle add the maven central repository to your repositories list :

mavenCentral()

Then you can just add the latest version to your build.

compile "org.java-websocket:Java-WebSocket:1.3.9"

Writing your own WebSocket Server

The org.java_websocket.server.WebSocketServer abstract class implements the server-side of the WebSocket Protocol. A WebSocket server by itself doesn't do anything except establish socket connections though HTTP. After that it's up to your subclass to add purpose.

An example for a WebSocketServer can be found in both the wiki and the example folder.

Writing your own WebSocket Client

The org.java_websocket.client.WebSocketClient abstract class can connect to valid WebSocket servers. The constructor expects a valid ws:// URI to connect to. Important events onOpen, onClose, onMessage and onError get fired throughout the life of the WebSocketClient, and must be implemented in your subclass.

An example for a WebSocketClient can be found in both the wiki and the example folder.

Examples

You can find a lot of examples here.

WSS Support

This library supports wss. To see how to use wss please take a look at the examples.

If you do not have a valid certificate in place then you will have to create a self signed one. Browsers will simply refuse the connection in case of a bad certificate and will not ask the user to accept it. So the first step will be to make a browser to accept your self signed certificate. ( https://bugzilla.mozilla.org/show_bug.cgi?id=594502 ).
If the websocket server url is wss://localhost:8000 visit the url https://localhost:8000 with your browser. The browser will recognize the handshake and allow you to accept the certificate. This technique is also demonstrated in this video.

The vm option -Djavax.net.debug=all can help to find out if there is a problem with the certificate.

It is currently not possible to accept ws and wss connections at the same time via the same websocket server instance.

For some reason Firefox does not allow multiple connections to the same wss server if the server uses a different port than the default port (443).

If you want to use wss on the android platfrom you should take a look at this.

I ( @Davidiusdadi ) would be glad if you would give some feedback whether wss is working fine for you or not.

Minimum Required JDK

Java-WebSocket is known to work with:

  • Java 1.6 and higher
  • Android 4.0 and higher

Other JRE implementations may work as well, but haven't been tested.

License

Everything found in this repo is licensed under an MIT license. See the LICENSE file for specifics.

java-websocket's People

Contributors

2fours avatar bendem avatar brushfiredigitalservices avatar ck1125 avatar cymp avatar danielywoo avatar davideandreuzza avatar davidiusdadi avatar deanrobertcook avatar dendritic avatar detro avatar duncan avatar eugene-kudelevsky avatar felixvf avatar ignaciomolina avatar jgautier avatar jlugia avatar jochembroekhoff avatar kamronbatman avatar marci4 avatar morkai avatar mpbarnwell avatar nathanielmichael avatar ottoallmendinger avatar philiproman avatar promatik avatar sattailanfear avatar shortstuffsushi avatar tootallnate avatar xcelder 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.