- 浏览: 1446867 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
c语言的socket基础http://haoningabc.iteye.com/blog/2305026
python的socket基础+select的方式http://haoningabc.iteye.com/blog/2305036
之后改造jslinux-network
把websocket和tap绑定
注意改了源码保证多个浏览器客户端可以同时ping通10.0.2.1
加的代码为
外层
共有变量
tuntapFD=-1
内层websocket代码
web_socket_transfer_data中添加
完整代码为
去happy吧
https://bitbucket.org/ivucica/websocketstuntap/
python的socket基础+select的方式http://haoningabc.iteye.com/blog/2305036
之后改造jslinux-network
把websocket和tap绑定
注意改了源码保证多个浏览器客户端可以同时ping通10.0.2.1
加的代码为
外层
共有变量
tuntapFD=-1
内层websocket代码
web_socket_transfer_data中添加
global tuntapFD if(tuntapFD == -1): tuntapFD, x, y = setupTUNTAP()
完整代码为
import sys, os, struct, select import base64 netBufferExpected = 0 def web_socket_do_extra_handshake(request): """Received Sec-WebSocket-Extensions header value is parsed into request.ws_requested_extensions. pywebsocket creates extension processors using it before do_extra_handshake call and never looks at it after the call. To reject requested extensions, clear the processor list. """ # for easier debugging: request.ws_extension_processors = [] tuntapFD=-1 def web_socket_transfer_data(request): """Echo. Same as echo_wsh.py.""" global tuntapFD if(tuntapFD == -1): tuntapFD, x, y = setupTUNTAP() print("--->tuntapFD end:"+str(tuntapFD)) # FIXME according to this post from 2010: # https://groups.google.com/forum/#!topic/pywebsocket/MY6HoG4KRCA # this method for fetching requestFD only works for standalone server requestFD = request.connection._request_handler.rfile._sock.fileno() socketlist = { requestFD:'websocket', #sys.stdin:'stdio', tuntapFD: 'tuntap' } netBuffer = "" while True: inputSockets = socketlist.keys() outputSockets = [] errorSockets = [] (inputReady, outputReady, errorOccurred) = select.select(inputSockets, outputSockets, errorSockets, 1) for each in inputReady: if socketlist[each] == 'websocket': netBuffer = process_requestFD(request, netBuffer) elif socketlist[each] == 'tuntap': output = os.read(tuntapFD, 8192) output = struct.pack('!H', len(output)) + output # network byte order short is "tapper"'s header request.ws_stream.send_message(output, binary=True) def process_requestFD(request, netBuffer): global netBufferExpected message = request.ws_stream.receive_message() if message is None: return netBuffer if isinstance(message, unicode): # text message - ignore it incomingData = base64.decodestring(message) pass else: incomingData = message #base64.decodestring(aNode.getCDATA()) if 1: # temp netBuffer += incomingData while len(netBuffer) >= netBufferExpected: if len(netBuffer) > 0 and netBufferExpected > 0: print " GOT ALL DATA!" try: dataToWrite = netBuffer[:netBufferExpected] print " (writing " + str(len(dataToWrite)) + " bytes)" os.write(tuntapFD, dataToWrite) netBuffer = netBuffer[netBufferExpected:] netBufferExpected = 0 print " (data remaining in buffer: " + str(len(netBuffer)) + ")" except Exception, e: print "problem" print e if len(netBuffer) > 2: netBufferExpected = struct.unpack('!H', netBuffer[0:2])[0] #netBufferExpected = socket.ntohs(netBufferExpected) netBuffer = netBuffer[2:] print " NOW EXPECTING " + str(netBufferExpected) if netBufferExpected > 1500 * 2: # more than 2x MTU? something is wrong print " (which is more than 2x MTU, so giving up)" netBuffer = "" netBufferExpected = 0 if len(netBuffer) == 0 and netBufferExpected == 0: break return netBuffer def setupTUNTAP(): #tuntapDevice = "tap2" tuntapDevice = "net/tun" # if len(sys.argv) >= 2: # tuntapDevice = sys.argv[1] ipAddress = "10.0.2.1" # if len(sys.argv) >= 3: # ipAddress = sys.argv[2] tuntapFD = os.open("/dev/" + tuntapDevice, os.O_RDWR) if tuntapDevice == "net/tun": # Linux specific code TUNSETIFF = 0x400454ca IFF_TUN = 0x0001 IFF_TAP = 0x0002 IFF_NO_PI = 0x1000 TUNMODE = IFF_TAP TUNMODE |= IFF_NO_PI # do not prepend protocol information from fcntl import ioctl ifs = ioctl(tuntapFD, TUNSETIFF, struct.pack("16sH", "websockettuntap%d", TUNMODE)) tuntapDevice = ifs[:16].strip("\x00") sys.stderr.write("tuntapdevice: " + tuntapDevice + "\n") os.system("ifconfig " + tuntapDevice + " inet " + ipAddress); return (tuntapFD, tuntapDevice, ipAddress) # vi:sts=4 sw=4 et
去happy吧
https://bitbucket.org/ivucica/websocketstuntap/
发表评论
-
websocket直播
2020-05-22 17:59 4361.websocket转发的最简单server 2.h5接收w ... -
sdl笔记
2019-01-31 17:19 691sdl教程教程 https://github.com/Twin ... -
tinyemu
2019-01-24 17:59 1402参考https://bellard.org/jslinux/t ... -
建立tap设备的c的代码
2019-01-08 19:09 440tapper.c #include <stdio.h& ... -
jslinux总结帖
2019-01-04 21:33 1023注意个问题: chrome不要用两个tab页,否则ping不通 ... -
br0和tap0的互相影响
2019-01-02 19:17 777转载 http://www.cnblogs.com/wlei/ ... -
openresty聊天室的helloworld
2018-04-22 19:25 728openresty的websocket + redis的sub ... -
openresty websocket
2018-04-18 17:08 1420mac安装openresty brew install o ... -
emscripten asm.js的helloworld
2018-03-01 20:15 1070mac下安装: brew install SDL2 SDL2_ ... -
nginx代理wss和https
2018-02-27 15:34 3862nginx启用ssl yum install openssl ... -
jslinux-deobfuscated-network
2017-02-13 22:37 617基础知识 查看网络包 tcpdump -i eth0 -e ... -
用buildroot为jslinux建立最小rootfs
2016-11-18 17:59 1212############################### ... -
jslinux带网络功能的内核
2016-11-15 15:35 753想重新编译jslinux-network 的内核,其实就是比f ... -
Tunnels with iproute2
2016-11-14 15:22 515copy from http://members.ferrar ... -
nginx rewrite替代apache rewrite
2016-10-18 20:30 788清理chrome的缓存 chrome://appcache-i ... -
qemu用tap方式启动vm的网络试验(ip route)
2016-09-14 11:29 2678ip route add 192.168.8.0/24 via ... -
socket的方式使用qemu建立虚拟机
2016-06-24 17:54 1806qemu的-net参数 -net nic 必须有,基本配置mo ... -
tap的方式使用qemu建立虚拟机NAT网络
2016-06-23 18:03 9509基本概念: vm:虚拟机 ... -
qemu用nat的方式使用tap建立虚拟机
2016-06-23 16:15 11普通桥接参考 http://haoningabc.iteye. ... -
tap的方式使用qemu建立虚拟机桥接网络
2016-06-22 20:53 7621需求:建立一个虚拟机,使网络和内网一样,当一台普通接入内网的服 ...
相关推荐
本篇博客介绍微信小程序中webSocket的使用方法,以及如何用局部网络建立webSocket连接,进行客户端与服务器之间的对话: webSocket简介 微信小程序端API调用 服务器端使用nodejs配置 演示websocket webSocket...
描述了websocket全局使用
配合http://blog.csdn.net/agroupofruffian/article/details/78994846这个文章,用来和unity做websocket连接使用
uniapp封装websocket,使用简单,下载复制进项目即可使用,统一使用json收发消息,区分业务类型。 1、使用方法,在需要使用的页面导入改文件(也可以挂载全局) 2、onLoad方法调用this.socketObj = new WebSocketIO...
java tomcat 7.0.42 websocket可使用java tomcat 7.0.42 websocket可使用java tomcat 7.0.42 websocket可使用java tomcat 7.0.42 websocket可使用
使用select模型实现WebSocket实现IM功能,项目中带有测试的网页客户端。具体可查看 https://blog.csdn.net/qq_34950682/article/details/105148477
thinkphp6使用workerman websocket连接
通过websocket通知fastreport进行打印,打印模板和数据由websocket消息进行传递
websocket的c#版本demo,包括服务器及客户端的具体使用代码
C# 开发 websocket 服务端和客户端 demo 使用,测试通过,服务端最小化到系统托盘,使用websocket-sharp
主要介绍了C#实现WebSocket协议客户端和服务器websocket sharp组件实例解析,包括websocket sharp组件的概念及使用方法,需要的朋友可以参考下
ios 实现websocket和h5 websocket通讯,实现双向联通。
使用thrift、websocket在javascript和c++之间建立rpc调用机制。 如果要使用js+html来写界面,cpp来写底层业务逻辑,这就非常有用了。 当然,如果底层不用cpp来写,也可以参考本代码的js对thrift的rpc包装。
vue2.0 根据elementui写的WebSocket心跳和聊天重连封装
qt 使用QWebSocket 创建websocket客户端来读取数据,异步链接,并且放入到线程中去执行,线程池的基础,代码使用两个用户,放入到一个线程中执行,同理,可以多个用户放入到多个线程中执行,为线程池执行websocket ...
websocket封装基于 1.websocket四大基础事件 2.扩展心跳检测与断线重连功能 3.核心对象封装,生成与销毁不需要客户端控制
uni-app中H5、PC端websocket使用
Spring+Netty+WebSocket实例,通用性还行,比较贴近生产,注释什么写的比较全
unty websocket 客户端 服务端 通信 使用WebSocketSharp框架
WebSocket开发教程和源代码例子(数据库数据变化是向前端推送数据)