leenjewel / node-kcp Goto Github PK
View Code? Open in Web Editor NEWKCP Protocol for Node.js
License: Other
KCP Protocol for Node.js
License: Other
When trying to require the npm lib in an Electron app, you get the following error
Uncaught (in promise) Error: Loading non-context-aware native module in renderer: '\\?\C:\Users\alona\dev\MyProj\app\node_modules\node-kcp-token\build\Release\kcp.node'. See https://github.com/electron/electron/issues/18397.
at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822)
at Module._extensions..node (node:internal/modules/cjs/loader:1226:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822)
at Module.load (node:internal/modules/cjs/loader:1011:32)
at Module._load (node:internal/modules/cjs/loader:846:12)
at f._load (node:electron/js2c/asar_bundle:2:13330)
at o._load (node:electron/js2c/renderer_init:2:3109)
at Module.require (node:internal/modules/cjs/loader:1035:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\alona\dev\MyProj\app\node_modules\node-kcp-token\index.js:1:173)
It appears that the following fork fixed it, however fails to compile on win 32 bit, upon npm install
https://github.com/bruce48x/node-kcp
https://github.com/leenjewel/node-kcp/blob/master/src/kcpobject.cc#L195
此处代码,似乎使用流的方式调用了ikcp_recv
。但KCP的默认工作模式是包模式,不应该进行拼接:skywind3000/kcp#238
DeprecationWarning: Invalid 'main' field in 'package.json' of 'node-kcp.node'. Please either fix that or report it to the module author
NAN_METHOD(KCPObject::Recv)
{
KCPObject* thiz = ObjectWrap::Unwrap(info.Holder());
int bufsize = 0;
char* buf = NULL;
int buflen = 0;
char* data = NULL;
int len = 0;
char* tmp = NULL;
int tmplen = 0;
while(1) {
tmplen = len;//chg one(修改1)
bufsize = ikcp_peeksize(thiz->kcp);
if (bufsize <= 0) {
break;
}
int align = bufsize % 4;
if (align) {
bufsize += 4 - align;
}
buf = (char*)malloc(bufsize);
buflen = ikcp_recv(thiz->kcp, buf, bufsize);
if (buflen <= 0) {
free(buf);
break;
}
len += buflen;
tmp = data;
data = (char*)malloc(len);
if (NULL != tmp) {
memcpy(data, tmp, tmplen);
free(tmp);
}
memcpy(data+tmplen, buf, buflen); //chg 2, copy need offset(修改2,开始没有偏移量,所以每次都拷贝在offset 0)
free(buf);
}
if (len > 0) {
info.GetReturnValue().Set(
Nan::CopyBuffer((const char*)data, len).ToLocalChecked()
);
}
free(data);
}
make: Entering directory `/data1/game-server/node_modules/node-kcp/build'
CC(target) Release/obj.target/kcp/src/kcp/ikcp.o
../src/kcp/ikcp.c: In function ‘ikcp_send’:
../src/kcp/ikcp.c:508:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (count >= IKCP_WND_RCV) return -2;
^
CXX(target) Release/obj.target/kcp/src/kcpobject.o
../src/kcpobject.cc: In static member function ‘static int node_kcp::KCPObject::kcp_output(const char*, int, ikcpcb*, void*)’:
../src/kcpobject.cc:67:37: warning: ‘v8::Localv8::Value Nan::Callback::Call(int, v8::Localv8::Value) const’ is deprecated (declared at ../../nan/nan.h:1740) [-Wdeprecated-declarations]
callback.Call(argc, argv);
^
../src/kcpobject.cc:76:37: warning: ‘v8::Localv8::Value Nan::Callback::Call(int, v8::Localv8::Value) const’ is deprecated (declared at ../../nan/nan.h:1740) [-Wdeprecated-declarations]
callback.Call(argc, argv);
^
../src/kcpobject.cc: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE node_kcp::KCPObject::Input(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/kcpobject.cc:223:36: error: no matching function for call to ‘v8::String::Value::Value(v8::Localv8::Value&)’
String::Value data(arg0);
node -v v12.14.0
node-gyp -v v5.0.5
npm-v 6.13.4
gcc 4.8.5
after command: npm install node-kcp
import node-kcp by the way: const kcp = require('node-kcp');
there was an error Module not found: Error: Can't resolve './build/Release/kcp'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.