socket_protobuf
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -10,3 +10,3 @@ import { PServer } from "../Server"; | ||
export interface Host { | ||
host: string; | ||
ip: string; | ||
port: number; | ||
@@ -19,3 +19,4 @@ /** | ||
export declare class Client { | ||
readonly host: string; | ||
private static index; | ||
readonly ip: string; | ||
readonly port: number; | ||
@@ -38,3 +39,3 @@ handlerMgr: HandlerMgr; | ||
private onError; | ||
startConnect(clientInfo: PServer, onServerInfo: (PServer: any) => void): void; | ||
startConnect(onServerInfo: (PServer: any) => void, clientInfo?: PServer): void; | ||
private start; | ||
@@ -41,0 +42,0 @@ private doConnect; |
@@ -20,3 +20,3 @@ "use strict"; | ||
this._connect_index = NetStatus.start; | ||
this.host = host.host; | ||
this.ip = host.ip; | ||
this.port = host.port; | ||
@@ -31,3 +31,3 @@ this._connect_delay = host.reconnect_delay_time * 1000; | ||
this.handlerMgr = new HandlerMgr_1.HandlerMgr(this._socket_client); | ||
this.lineLogInfo(this.lineInfo + "服务器---连接成功\n\n------正在请求服务器数据...\n"); | ||
this.lineLogInfo(this.lineInfo + "服务器---连接成功\n\n正在请求服务器数据...\n"); | ||
} | ||
@@ -58,3 +58,17 @@ async onMessage(pkg) { | ||
} | ||
startConnect(clientInfo, onServerInfo) { | ||
startConnect(onServerInfo, clientInfo = null) { | ||
if (null == clientInfo) { | ||
const os = require("os"); | ||
//物理服务器配制唯一编号 | ||
const machineId = Client.index++ * 100 + Math.floor(Date.now() / 1000); | ||
clientInfo = new Server_1.PServer({ | ||
name: os.hostname(), | ||
version: machineId.toString(32), | ||
ip: this.ip, | ||
port: this.port, | ||
machineId: machineId, | ||
other1: [], | ||
other2: [] //其它参数2 | ||
}); | ||
} | ||
this.clientInfo = clientInfo; | ||
@@ -73,5 +87,5 @@ this.onServerInfo = onServerInfo; | ||
doConnect() { | ||
this.lineLogInfo("Web_Sever服务器---连接开始:" + this.host + ":" + this.port); | ||
this.lineLogInfo("Web_Sever服务器---连接开始:" + this.ip + ":" + this.port); | ||
this._connect_stat = NetStatus.connecting; | ||
this._socket_client = new ServerSocket_1.ServerSocket(this.host, this.port, [ | ||
this._socket_client = new ServerSocket_1.ServerSocket(this.ip, this.port, [ | ||
this.onConnected.bind(this), | ||
@@ -116,3 +130,3 @@ this.onMessage.bind(this), | ||
get lineInfo() { | ||
return "Sever线路:" + this.host + ":" + this.port; | ||
return "Sever线路:" + this.ip + ":" + this.port; | ||
} | ||
@@ -129,2 +143,3 @@ lineLogInfo(msg) { | ||
} | ||
Client.index = 1; | ||
exports.Client = Client; |
@@ -18,3 +18,2 @@ import { Socket } from "net"; | ||
sendPkg(pkg: SocketPackage): void; | ||
getId(): number; | ||
isActive(): boolean; | ||
@@ -21,0 +20,0 @@ dispose(): void; |
@@ -58,5 +58,2 @@ "use strict"; | ||
} | ||
getId() { | ||
return this.id; | ||
} | ||
isActive() { | ||
@@ -111,3 +108,3 @@ return this._is_alive; | ||
this._is_alive = false; | ||
this.server.removeClient(this.getId()); | ||
this.server.removeClient(this.id); | ||
} | ||
@@ -114,0 +111,0 @@ addEvent() { |
{ | ||
"name": "socket_protobuf", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "socket发送protobuf二进制流的SDK", | ||
@@ -5,0 +5,0 @@ "main": "App.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43677
1208