zoukankan      html  css  js  c++  java
  • socket.io的抽象实现:engine.io

    engine.io是一个socket.io的抽象实现,作为socket.io的服务器和浏览器之间交换的数据的传输层。它不会取代Socket.IO,它只是抽象出固有的复杂性,支持多种浏览器,设备和网络的实时数据交换。Server (A) Listening on a port

    1 var engine = require('engine.io')
    2   , server = engine.listen(80)
    3  
    4 server.on('connection', function (socket) {
    5   socket.send('utf 8 string');
    6 });

    (B) Intercepting requests for a http.Server

    1 var engine = require('engine.io')
    2   , http = require('http').createServer().listen(3000)
    3   , server = engine.attach(http)
    4  
    5 server.on('connection', function (socket) {
    6   socket.on('message', function () { });
    7   socket.on('close', function () { });
    8 });

    (C) Passing in requests

    01 var engine = require('engine.io')
    02   , server = new engine.Server()
    03  
    04 server.on('connection', function (socket) {
    05   socket.send('hi');
    06 });
    07  
    08 // …
    09 httpServer.on('upgrade', function (req, socket, head) {
    10   server.handleUpgrade(req, socket, head);
    11 });
    12 httpServer.on('request', function (req, res) {
    13   server.handleRequest(req, res);
    14 });

    Client

    1 <script src="/path/to/engine.io.js"></script>
    2 <script>
    3   var socket = new eio.Socket('ws://localhost/');
    4   socket.on('open', function () {
    5     socket.on('message', function (data) { });
    6     socket.on('close', function () { });
    7   });
    8 </script>

    项目主页:http://www.open-open.com/lib/view/home/1384093598133

  • 相关阅读:
    spring mvc 分页
    get/post时中文乱码问题的解决办法
    mysql-day01
    servler配置
    idea
    springMvc 核心配置
    ServletRequest面试题
    Servlet面试题
    Http面试题
    测试文件
  • 原文地址:https://www.cnblogs.com/aibo/p/3438533.html
Copyright © 2011-2022 走看看