node.js — отправка 250 мс UDP-цены за соединение через сокет из C ++ к сбоям процессов nodejs, почему?

Попытка отправить ценовые тики UDP от процесса «говорящего» в C ++ процессу «слушателя» nodejs, и я получаю сбой.

Разговор тика и слушание работают для процессов C ++ — C ++. Когда я добавил слушателя части Nodejs, он взорвался.

Любое понимание? Спасибо, Кит: ^)

Данные тика Выглядит хорошо:

Price unicasted: 49.58
Price unicasted: 50.00
Price unicasted: 50.24
Price unicasted: 50.09
Price unicasted: 49.81

C ++ Talker

#define SERVERPORT "4950"
int main(int argc, char *argv[])
{
int sockfd;
struct addrinfo hints, *servinfo;
int rv;
size_t numbytes;
char* address = "192.168.1.100";

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = 0;

if ((rv = getaddrinfo(address, SERVERPORT, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
sockfd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);

char myPrice[7];
float f;
while(1) {
f = randPrice();
ftoa(f, myPrice, 2); // Convert price to string
myPrice[5] = '\n'; myPrice[6] = '\0';

std::cout << "Price unicasted: " << myPrice;
if ((numbytes = sendto(sockfd, myPrice, strlen(myPrice), 0, servinfo->ai_addr, servinfo->ai_addrlen)) == -1) {
perror("talker: sendto");
exit(1);
}
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
freeaddrinfo(servinfo);
close(sockfd);

return 0;
}

Node.js Listener

var PORT = 4950;
var HOST = '192.168.1.100';

var dgram = require('dgram');
var server = dgram.createSocket('udp4');

server.on('listening', function () {
var address = server.address();
console.log('UDP Server listening on ' + address.address + ":" + address.port);
});

while(1) {
server.on('message', function (message, remote) {
console.log(remote.address + ':' + remote.port +' - ' + message);
});
}

server.bind(PORT, HOST);

ошибка Ик!

pickledEgg> node udp.listener.js
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
==== C stack trace ===============================
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
==== C stack trace ===============================
<--- Last few GCs --->

[14801:0x102806800]    13404 ms: Mark-sweep 1385.7 (1425.8) -> 1385.7 (1441.3) MB, 1099.6 / 0.0 ms  allocation failure scavenge might not succeed
[14801:0x102806800]    14533 ms: Mark-sweep 1400.7 (1441.3) -> 1400.7 (1441.8) MB, 1099.3 / 0.0 ms  allocation failure scavenge might not succeed
[14801:0x102806800]    15852 ms: Mark-sweep 1401.5 (1441.8) -> 1401.5 (1456.3) MB, 1317.5 / 0.0 ms  allocation failure scavenge might not succeed

<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::AllocateTargetObject(v8::internal::HeapObject*, v8::internal::HeapObject**) [/usr/local/bin/node]
5: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*) [/usr/local/bin/node]
6: v8::internal::MarkCompactCollector::Evacuator::EvacuatePage(v8::internal::Page*) [/usr/local/bin/node]
7: v8::internal::PageParallelJob<v8::internal::EvacuationJobTraits>::Task::RunInternal() [/usr/local/bin/node]
8: v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [/usr/local/bin/node]
9: v8::internal::MarkCompactCollector::EvacuateNewSpaceAndCandidates() [/usr/local/bin/node]
10: v8::internal::MarkCompactCollector::CollectGarbage() [/usr/local/bin/node]
11:     0   node                                0x0000000100bf1593 v8::base::debug::StackTrace::StackTrace() + 19
1   node                                0x0000000100bee739 V8_Fatal + 233
2   node                                0x0000000100143e48 v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) + 744
3   node                                0x00000001005e03bb v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::AllocateTargetObject(v8::internal::HeapObject*, v8::internal::HeapObject**) + 1019
4   node                                0x00000001005df6be v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*) + 318
5   node                                0x00000001005eb8eb v8::internal::MarkCompactCollector::Evacuator::EvacuatePage(v8::internal::Page*) + 235
6   node                                0x00000001005eb786 v8::internal::PageParallelJob<v8::internal::EvacuationJobTraits>::Task::RunInternal() + 198
7   node                                0x0000000100b067d9 v8::platform::WorkerThread::Run() + 25
8   node                                0x0000000100bf3187 v8::base::ThreadEntry(void*) + 87
9   libsystem_pthread.dylib             0x00007fff9250bc13 _pthread_body + 131
10  libsystem_pthread.dylib             0x00007fff9250bb90 _pthread_body + 0
11  libsystem_pthread.dylib             0x00007fff92509375 thread_start + 13
Illegal instruction: 4

РЕДАКТИРОВАТЬ 1: Последующая ошибка

node udp.listener.js
events.js:182
throw er; // Unhandled 'error' event
^

Error: bind EADDRINUSE 192.168.1.100:4950
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at _handle.lookup (dgram.js:242:18)
at _combinedTickCallback (internal/process/next_tick.js:105:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3

0

Решение

Вы, кажется, вставить message обработчики событий в бесконечном цикле while(1) так что вы получаете ошибку памяти. Скорее всего, вам нужно установить обработчик только один раз.

1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]