When I tried to send message to a testnet node, an event “disconnect” will be always emitted. But when I tried with mainnet, this issues does not appear.
Is there any additional condition for testnet?
My snippet likes below.
var bitcore = require(‘bitcore-lib’);
var Peer = require(‘bitcore-p2p’).Peer;
var Networks = bitcore.Networks;
var p2p = require(‘bitcore-p2p’)
var Messages = p2p.Messages;
var peer = new Peer({host: ‘104.237.131.138’, port: 18333, network: Networks.testnet})
peer.on(‘ready’, function() {
// peer info
console.log(peer.version, peer.subversion, peer.bestHeight);
var messages = new Messages();
var message = messages.Ping();
// var message = messages.GetAddr()
peer.sendMessage(message);
});
peer.on(‘connect’, function() {
// peer info
console.log(“Node is connecting”);
});
peer.on(‘connected’, function() {
// peer info
console.log(“Node is connected”);
});
peer.on(‘disconnect’, function() {
console.log(‘connection closed’);
});
peer.on(‘addr’, function(message) {
// message.addresses[]
message.addresses.forEach(function(address) {
// do something
console.log('Address is ’ + JSON.stringify(address))
});
});
peer.connect();
I have found out the reason. The instance of Messages must be declared with network is testnet as example below.
var messages = new Messages({network: Networks.testnet});
Hello ,
When I tried to send message to a testnet node, an event “disconnect” will be always emitted. But when I tried with mainnet, this issues does not appear. Is there any additional condition for testnet?
My snippet likes below.