7f 中文文档教程

发布于 10年前 浏览 30 项目主页 更新于 3年前

lib7f

Node.js 的 7F 协议库

构建状态依赖状态 NPM 版本

Usage

npm install 7f

Server

lib7f  = require "7f"
server = new lib7f.Server
server.on "client", (client) ->
  client.on "message", (msg) ->
    console.log msg
    header = {nr: 1}
    advancedHeader =
      logicalNr:  1245
      command:    lib7f.constants.Command.TO
      type:       lib7f.constants.DataType.BYTEARRAY
      count:      3
    data = new Buffer 7
    msg = new lib7f.Message header, advancedHeader, data
    client.send msg

server.on "reconnect", (client) ->
  console.log "client #{client.id} has reconnected"

server.connect -> # the server is ready

也可以指定端口,服务器应该到哪个服务器地址 绑定到服务器规格编号及其登录功能 ID:

server = new lib7f.Server
  host: "192.168.10.30"
  port: 5010
  specificationNr: 8
  loginFunctionId: 5

Client

lib7f  = require "7f"

client = new lib7f.Client 7,
  host: "192.168.0.100"
  port: 5010
  specificationNr: 3
  loginFunctionId: 9

client.on "message", (msg) ->
  console.log msg
  header = {nr: 4}
  advancedHeader =
    logicalNr:  54
    command:    lib7f.constants.Command.FETCH
    type:       lib7f.constants.DataType.WORD
    count:      9
  data = new Buffer 33
  msg = new lib7f.Message header, advancedHeader, data
  client.send msg

client.on "error", (err) ->
  console.log "something went wrong"

client.on "login", ->
  console.log "client is now logged in"

client.on "connect", ->
  console.log "client is connected"
  client.login()

client.on "disconnect", ->
  console.log "client is now disconnected"

client.connect()

License

GPLv3

lib7f

7F protocol library for Node.js

Build StatusDependency StatusNPM version

Usage

npm install 7f

Server

lib7f  = require "7f"
server = new lib7f.Server
server.on "client", (client) ->
  client.on "message", (msg) ->
    console.log msg
    header = {nr: 1}
    advancedHeader =
      logicalNr:  1245
      command:    lib7f.constants.Command.TO
      type:       lib7f.constants.DataType.BYTEARRAY
      count:      3
    data = new Buffer 7
    msg = new lib7f.Message header, advancedHeader, data
    client.send msg

server.on "reconnect", (client) ->
  console.log "client #{client.id} has reconnected"

server.connect -> # the server is ready

You can also specify the port, the server address to which the server should be bound to, the servers specification number and it's login function ID:

server = new lib7f.Server
  host: "192.168.10.30"
  port: 5010
  specificationNr: 8
  loginFunctionId: 5

Client

lib7f  = require "7f"

client = new lib7f.Client 7,
  host: "192.168.0.100"
  port: 5010
  specificationNr: 3
  loginFunctionId: 9

client.on "message", (msg) ->
  console.log msg
  header = {nr: 4}
  advancedHeader =
    logicalNr:  54
    command:    lib7f.constants.Command.FETCH
    type:       lib7f.constants.DataType.WORD
    count:      9
  data = new Buffer 33
  msg = new lib7f.Message header, advancedHeader, data
  client.send msg

client.on "error", (err) ->
  console.log "something went wrong"

client.on "login", ->
  console.log "client is now logged in"

client.on "connect", ->
  console.log "client is connected"
  client.login()

client.on "disconnect", ->
  console.log "client is now disconnected"

client.connect()

License

GPLv3

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文