send() hangs

Post Reply
Posts: 1
Joined: Sun Apr 23, 2017 4:09 pm

send() hangs

Post by ronaldyorts » Sun Apr 23, 2017 4:32 pm

I want to send a string to my nodejs TCP server.

This is the code for my client (C++):

Code: Select all

#include <nds.h>
#include <dswifi9.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string>

std::string hostname = "hostname";
int port = 61733;
int sock;

int main(){
    Connect(); //function to connect with a WiFi network

    unsigned long lastSendTime = 0;
    unsigned long sendInterval = 200; //send a message every 200 milliseconds
    unsigned int nMsgSent = 0;

    while (1){
        unsigned long now = milliseconds(); //function to get the time in milliseconds
        if ((now - lastSendTime) > sendInterval){
            std::string request = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
            request += request;
            request += std::to_string(nMsgSent);
            request += "\n";

            int sendResult = ::send(sock, request.c_str(), request.length(), 0);
            iprintf("req(%d): %d\n", nMsgSent, sendResult);

            lastSendTime = now;
    return 0;
The client only sends about 180 messages and then send hangs. The server only receives ~120 messages.
When I increase the length of the request, the client sends less requests and when I decrease the length, the clients sends more requests.
I also found out that when I decrease the sendInterval, I can send more requests before send hangs.
I don't know what I'm doing wrong. When I execute similar code with a nodejs client, everything is okay, so the problem lies with the C++ client.

I also asked this question on Stack Overflow(, but nobody could help me so far :( .
The server code and some other things are mentioned in my question on Stack Overflow.
It would be great if somebody could help me with this.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests