Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

io-request

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-request

https://github.com/bramblex/io-request.git

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

IORequest

介绍

IORequest 是一个基于 socket.io 的双向 request 库。

IORequest 同时支持客户端向服务端发送请求以及服务端向客户端发送请求。

安装

node

npm install io-request

浏览器

<script src="dist/browser/io-request-client.js"></script>

用法

服务端

const server = require('http').createServer()
const io = require('socket.io')(server)

const {IORequestServer} = require('io-request')

const ioReqServer = new IORequestServer(io)

// 定义服务端 echo 请求的 handler
ioReqServer.handle('echo', ({response, data}) => {
  response(data)
})

io.on('connection', socket => {

  socket.on('io-connect', () => {
    // 向客户端端发送 echo 请求
    socket.ioRequest({method: 'echo', data: 'hello client'})
      .then(data => console.log('客户端返回:' + JSON.stringify(data)))
  })

})

server.listen(8080)

客户端


const socket = io()
const ioReqClient = new IORequestClient(socket)

// 定义客户端 echo 请求的 handler
ioReqClient.handle('echo', ({response, data}) => {
  response(data)
})

socket.on('io-connect', () => {
  socket.ioRequest({method: 'echo', data: 'hello server'})
    .then(data => console.log('服务端返回:' + data))
})

Keywords

FAQs

Package last updated on 13 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc