All Projects → playay → ws2s

playay / ws2s

Licence: MIT license
ws2s(websocket to socket)--bring socket to browser-side js.

Programming Languages

python
139335 projects - #7 most used programming language
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to ws2s

realtime-csharp
A C# client library for supabase/realtime.
Stars: ✭ 35 (-30%)
Mutual labels:  socket
SocketIOUnity
A Wrapper for socket.io-client-csharp to work with Unity.
Stars: ✭ 69 (+38%)
Mutual labels:  socket
TweetMigration
A WebGL heatmap of global Twitter activity
Stars: ✭ 42 (-16%)
Mutual labels:  socket
express-boilerplate
ExpressJS boilerplate with Socket.IO, Mongoose for scalable projects.
Stars: ✭ 83 (+66%)
Mutual labels:  socket
epoller
epoll implementation for connections in Linux, MacOS and Windows
Stars: ✭ 58 (+16%)
Mutual labels:  socket
video-chat
Simple Web Application that offer you to create video meeting room using WebRTC and Socket.
Stars: ✭ 32 (-36%)
Mutual labels:  socket
phaChat
a web chat by node.js 一个基于 node.js 的多人 web 聊天室
Stars: ✭ 18 (-64%)
Mutual labels:  socket
react-webrtc-chat
React WebRTC chat
Stars: ✭ 39 (-22%)
Mutual labels:  socket
AsyncSocket
Asynchronous socket (client+server) continues communications
Stars: ✭ 26 (-48%)
Mutual labels:  socket
LittleDrawBoard AN
基于socket实现的pc端和android端同步绘画板_ANDROID源码
Stars: ✭ 30 (-40%)
Mutual labels:  socket
EasySharpFrame
Easy .NET Develop Frame.
Stars: ✭ 73 (+46%)
Mutual labels:  socket
ng2-STOMP-Over-WebSocket
STOMP Over WebSocket service for angular2
Stars: ✭ 35 (-30%)
Mutual labels:  socket
freebind
IPv4 and IPv6 address rate limiting evasion tool
Stars: ✭ 88 (+76%)
Mutual labels:  socket
net-Socket
A minimalist wrapper around System.Net.Sockets.Socket.
Stars: ✭ 21 (-58%)
Mutual labels:  socket
DatagramTunneler
Simple C++ cross-platform client/server app forwarding UDP datagrams through a TCP connection.
Stars: ✭ 116 (+132%)
Mutual labels:  socket
lce
linux网络编程框架(C++)基于Reactor事件机制,支持线程池,异步非阻塞,高并发,高性能
Stars: ✭ 61 (+22%)
Mutual labels:  socket
HiFramework.Unity
Based on component to manage project's core logic and module used in unity3d
Stars: ✭ 22 (-56%)
Mutual labels:  socket
asynchronous
A D port of Python's asyncio library
Stars: ✭ 35 (-30%)
Mutual labels:  socket
TCP-IP-NP
《TCP/IP网络编程》((韩)尹圣雨) 学习笔记
Stars: ✭ 66 (+32%)
Mutual labels:  socket
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (+34%)
Mutual labels:  socket

also see: https://gitee.com/apihub/ws2s

ws2s--bring socket to browser-side js

ws2s(websocket to socket) is a websocket server that handle socket(tcp)s.

the simplest workflow might be like this:

  1. a websocket client(we called "ws") ask ws2s_server to create a socket(we called "s") for it.
  2. "ws" ask ws2s_server to use "s" to send data.
  3. when "s" received data, ws2s_server will notify "ws" with the received data.

with this workflow, javaScript running on a browser got the ability to use socket.

client case

  • a ws2s server at wss://ws2s.feling.net/ is ready for test case.
  • an online redis gui client powered by ws2s is provided at https://feling.net/redis/.

use origin javaScript

var ws = new WebSocket("wss://ws2s.feling.net/")
ws.onmessage = (event) => {
    console.log("onmessage: ", event.data)
}
ws.onopen = () => {
    console.log("onopen")
    ws.send(JSON.stringify(
        {
            command: "connect",
            host: "feling.net",
            port: 80
        }
    ))
    ws.send(JSON.stringify(
        {
            command: "send",
            data: "GET / HTTP/1.1\r\nHost: feling.net\r\nConnection: close\r\n\r\n"
        }
    ))
}
ws.onclose = () => {
    console.log("onclose")
}

use ws2s.js

var socket = new WS2S("wss://ws2s.feling.net/").newSocket()

$('#connect-button').bind("click", () => {
    socket.connect("feling.net", 80)
})

$('#send-button').bind("click",  () => {
    socket.send("GET / HTTP/1.1\r\nHost: feling.net\r\nConnection: close\r\n\r\n")
})

socket.onRecv = (data) => {
    console.log('onRecv', data)
}

install

ws2s works with py2、py3 on Linux、OSX. Windows users please try Windows Subsystem for Linux(WSL).

It is recommended to install from github:

pip install git+https://github.com/playay/ws2s --upgrade

you can also install ws2s from pypi:

pip install ws2s-python --upgrade

after installed ws2s:
ws2sd command can be used in shell,
~/.ws2s/ directory will be created when you exec ws2sd

config

config file is store at ~/.ws2s/config.json. modify it then exec ws2sd restart

start on boot

at see this wiki

protocol

request

here are some examples of requests:

{
    "command": "connect",
    "host":"127.0.0.1",
    "port":80
}
{
    "command": "send",
    "data":"GET / HTTP/1.1\r\nHost: 127.0.0.1\r\nConnection: close\r\n\r\n"
}

you can find out that:

  1. message(we called request) send to ws2s_sever is a json format string.
  2. a command field is required. other fields are dependent on different commands
  3. this wiki describes details of each command.

response

message(we called response) received from ws2s_sever, is a json format string too:

{
    "success": true,
    "code": -1,
    "message": "recv data",
    "data": "JDINCk9LDQo="
}
As the example above:    
- "message" field is for human.   
- "success" field can be ignored.     

when "code" field = -1, "data" field is presented.     
    that means ws2s_server received data from peer. "data" is a base64 string representing a byte array.     

when "code" field = 0.      
    usually means ws2s_server successfully completed the most recent command    

when "code" field > 0.      
    means something is not normal:      
    when "code" = 1:    
        unknown exception, you can submit an issue to ws2s    

    when "code" = 2:    
        ConnectionRefusedError raisesd when ws2s_server try to   
        connect host:port you specified    

    when "code" = 3:    
        IllegalSocketState, just reSend an "connect" request like:    
        {"command":"connect","host":"127.0.0.1","port":80}    

    when "code" = 4:    
        usually means you want ws2s_server to connect 127.0.0.1, but ws2s_server refused     
        to do that. this feature is configurable in `~/.ws2s/config.json`    
    
    when "code" = 5:    
        socket connection closed by socket server you connected to    

    when "code" = 6:    
        failed to open ssh tunnel    

dev

pipenv shell





python setup.py bdist_wheel
python setup.py sdist
twine upload  dist/*
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].