View unanswered posts | View active topics It is currently Thu Jan 24, 2019 1:19 pm

Reply to topic  [ 1 post ] 
 send() hangs 
Author Message

Joined: Sun Apr 23, 2017 4:09 pm
Posts: 1
I want to send a string to my nodejs TCP server.

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

#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.

Sun Apr 23, 2017 4:32 pm
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: Bing [Bot] and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at Fast, secure and Free Open Source software downloads