Some problems about the raw-socket in Node.js - node.js

My operating system is Windows 10 Version 10586 and node.js is Version 4.4.5.
When I use the module raw-socket follow the example in this page
https://github.com/stephenwvickers/node-raw-socket
When running code like this:
var raw = require ("raw-socket");
var socket = raw.createSocket ({protocol: raw.Protocol.None});
I got following error:
C:\Users\KEEY\node_modules\raw-socket\index.js:47
this.wrap = new raw.SocketWrap (
^
Error: ��һ�ַ���Ȩ�޲������ķ�ʽ����һ�������׽��ֵij��ԡ�
at Error (native)
at new Socket (C:\Users\KEEY\node_modules\raw-socket\index.js:47:14)
at Object.exports.createSocket (C:\Users\KEEY\node_modules\raw-socket\index.js:202:9)
at Object.<anonymous> (C:\Users\KEEY\Desktop\node\raw-socket\demo.js:2:18)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
[Finished in 0.2s with exit code 1]
How to solve it?

Thanks for everyone's help.
I email Stephen Vickers,the author of the module raw-socket,the source of problem is that
Stephen Vickers:
It looks like you don't have permissions to open raw sockets on that platform.
Then I run it as administrator, it works!
Thank you,Stephen Vickers

try this
var socket = raw.createSocket ({
protocol: raw.Protocol.None,
socketOption: raw.SocketOption.IPV6_HDRINCL
});

Related

Wit ai based node.js code on running with forever command throws error

I am trying to develop a facebook messenger bot application with the use of wit.ai framework. The application runs fine when i run my node.js code with command
node app.js
But when i try to run it with the use of forever command like below i am getting the following error in wit library file.
forever -o out.log -e err.log start app.js
string_decoder.js:66
var buflen = buffer.length;
^
TypeError: Cannot read property 'length' of null
at StringDecoder.write (string_decoder.js:66:22)
at Interface._normalWrite (readline.js:319:30)
at Interface.write (readline.js:310:49)
at message.converse.makeActionCallback.runActions.interactive.rl.on [as
interactive] (/home/user/example/lib/wit.js:289:13)
at Object. (/home/user/example/app.js:540:8) at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
Any help will be highly appreciated!!
I found a workaround for this which was suggested by someone else in github. In wit.js line 300 replace
this.rl.write(null, {ctrl: true, name: 'e'});
with
this.rl.write( '', {ctrl: true, name: 'e'});

node-gcm : TypeError: gcm.Message is not a function

I am getting this error when i try to use node-gcm in my code. I have included it as per standard methods require('node-gcm')
var message = new gcm.Message();
^
TypeError: gcm.Message is not a function
at Object.<anonymous> (/home/parashar/Downloads/opentsdb.js:13:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
Can someone help me out?
Judging by this issue, it may be that an alpha version of node-gcm was mistakenly published as being the latest stable one.
Until that's fixed, you can try this to get your code working again:
npm install node-gcm#0
EDIT: the issue should be fixed now.

Nodejs module not found error

Hi All I am very new to the nodejs.
I am trying to install the cryptlib module by using the following command for this:
npm install cryptlib
It installing successfully. When I move to myproject ->node_modules the folder called cryptlib is there.
But when I include it in my server.js as follow
var CryptLib = require('cryptlib'),
_crypt = new CryptLib(),
plainText = 'This is the text to be encrypted',
iv = _crypt.generateRandomIV(16), //16 bytes = 128 bit
key = _crypt.getHashSha256('my secret key', 32), //32 bytes = 256 bits
cypherText = _crypt.encrypt(plainText, key, iv),
originalText = _crypt.decrypt(cypherText, key, iv);
Then its throwing an error
module.js:340
throw err;
^
Error: Cannot find module 'cryptlib'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/html/testing/server.js:9:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
So how can I fix this error? Any help would be appriciated.
Sorry I dont have enough points to reply as a comment before this.
I have updated cryptlib on npm to version 1.0.3 to address this issue. It should work now. Thank you 王庭茂 for your excellent effort.
Also thank you user3446467 for using the module.
If you encounter any further issues please let me know.
It seems to be the problem of the original package. I have sent a pull request to fix this problem. For now, just do what I have done on the pull request and it should work.

Node.js Just starting

i'm following the lynda.com tutorials, love this site, i got my hello world with console.log()
my next task is to try this script
var os = required('os');
var message = 'This script is running on Node.js ' + process.version + ' on a '
+ os.type() + '-based operating system.';
console.log(message);
my error in the terminal
ReferenceError: required is not defined
at Object.<anonymous> (/Users/ArtSir/nodeJS/script.js:1:72)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
I double checked my spelling and check my semicolons (that doesn't really matter in node.js like javascript right) but yea any help? i just started. I don't understand why required is not defined, i installed node. was i suppose to install 'os'?
It's require, withoud d:
var os = require('os');

nodeJS ReferenceError : navigator is not defined.

Hello I'm trying to make some Javascript files working on nodeJS everything is well set however here is the error I get :
C:\>node myServer.js
C:\myFunctionsCallTest.js:750
if( (j_lm && (navigator.appName == "Microsoft Internet Explorer")) || navigato
^
ReferenceError: navigator is not defined
at Object.<anonymous> (C:\myFunctionsCallTest.js:750:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\myServer.js:1:79)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
C:\>
The files I'm using are :
myServer.js
var my_module = require("./myFunctionsCallTest.js");
console.log("RSA encrypted message :"+ my_module.Encrypt("myKey","myMessage"));
myFunctionsCallTest.js //This file contains some call of prototypes like :
.....................................
RSAKey.prototype.setPublic = RSASetPublic;
RSAKey.prototype._short_encrypt = RSAEncrypt;
RSAKey.prototype.encrypt = RSAEncryptLong;
RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
..............................................
Any idea from where this issue could come?
Thanks.
It looks like you're using Tom Wu's BitInteger and RSA JavaScript library. This library was designed for use in the browser and doesn't work quite right in Node.js.
Luckily, someone has already gone through the work of packaging this library in a Node.js compatible format; it's on GitHub at https://github.com/eschnou/node-bignumber and available via npm as the package "bignumber", and comes with a nice example.

Resources