Giter VIP home page Giter VIP logo

websockets.jl's Introduction

WebSockets.jl

This is a server-side implementation of the WebSockets protocol in Julia. If you want to write a web app in Julia that uses websockets, you'll need this package.

WebSockets.jl is most useful in combination with HttpServer.jl, which takes care of accepting connections and parsing HTTP requests. As you can see in the example code at the bottom of the README, you just define a function that takes a request and a client. The request is an HTTP Request from HttpCommon.jl; the client is a WebSocket, from this package. Your server can write data to the WebSocket, read data from it, send ping or pong messages, or close the connection.

On a historical note, this pacakage started out as part of webstack.jl, and became it's own repo when webstack.jl was fragmented in preparation for making each piece into it's own package.

WebSockets.jl, like the rest of webstack.jl, has only been tested with the development version of Julia. You should install Julia from source if you want to use WebSockets.jl.

##Installation/Setup

# in REQUIRE
WebSockets 0.0.1

# in REPL
julia> Pkg2.add("WebSockets")

This will install WebSockets.jl and it's dependencies (HttpServer.jl, HttpCommon.jl, HttpParser.jl).

At this point, you can test that it all works by cding into the ~/.julia/WebSockets.jl directory and running julia examples/chat.jl. Open localhost:8000 in a browser that supports WebSockets, and you should see a basic IRC-like chat application.

##Echo server example:

using HttpServer
using WebSockets

wsh = WebSocketHandler() do req,client
    while true
        msg = read(client)
        write(client, msg)
    end
  end

server = Server(wsh)
run(server,8080)

To play with a WebSockets echo server, you can:

  1. Paste the above code in to the Julia REPL
  2. Open localhost:8080 in Chrome
  3. Open the Chrome developers tools console
  4. Type ws = new WebSocket("ws://localhost:8080"); into the console
  5. Type ws.send("hi") into the console.
  6. Switch to the 'Network' tab; click on the request; click on the 'frames' tab.
  7. You will see the two frames containing "hi": one sent and one received.
:::::::::::::
::         ::
:: Made at ::
::         ::
:::::::::::::
     ::
Hacker School
:::::::::::::

websockets.jl's People

Contributors

astrieanna avatar despeset avatar zachallaun avatar dcjones avatar

Watchers

 avatar James Cloos avatar  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.