0

This sends data only once which seems irrational to me as it is in a for loop:

char* hello;
for (int i = 0; i < 10; i++) {

    hello = "Hello world!\n";
    if (UDT::ERROR == UDT::send(client, hello, strlen(hello) + 1, 0))
    {
        cout << "send: " << UDT::getlasterror().getErrorMessage();
    }

}

Shouldn't it send data 10 times? I don't understand it. Here is the whole program (it's quite short):

int main()
{
    UDTSOCKET client;
    sockaddr_in serv_addr;
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(9000);
    inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
    memset(&(serv_addr.sin_zero), '\0', 8);

    client = UDT::socket(AF_INET, SOCK_STREAM, 0);

    // connect to the server, implict bind
    if (UDT::ERROR == UDT::connect(client, (sockaddr*)&serv_addr, sizeof(serv_addr)))
    {
        cout << "connect: " << UDT::getlasterror().getErrorMessage();
    }

    char* hello;
    for (int i = 0; i < 10; i++) {

        hello = "Hello world!\n";

        if (UDT::ERROR == UDT::send(client, hello, strlen(hello) + 1, 0))
        {
            cout << "send: " << UDT::getlasterror().getErrorMessage();
        }

    }

    UDT::close(client);

    system("pause");
}
OrangeDog
  • 36,653
  • 12
  • 122
  • 207
Richard Knop
  • 81,041
  • 149
  • 392
  • 552

3 Answers3

1

Does it go through the loop 10 times, or only go through the loop once?

I'm not familiar with the library you're using, but I didn't see any kind of flush command. If it goes through the loop 10 times but only sends data once, you might need to flush.

John Dibling
  • 99,718
  • 31
  • 186
  • 324
  • It goes through the loop 10 times. The library documentation is here: http://udt.sourceforge.net/udt4/index.htm. How should I flush? I am not very good with C/C++. I just followed some code snippets from the documentation. – Richard Knop Nov 20 '10 at 14:50
  • How do you determin it only sends one message ? Did you monitor with wireshark ? – nos Nov 20 '10 at 15:19
1

Have you checked the server side code. Client is doing sends in a for loop, how is the server side receiving them?

Edit: In reference to your post here. If your server code looks like this, it will receive only once. The server is getting the connection from the client then receives once then again waits for connection from a client. But the client keeps sending in a loop. Its just a guess that this is your server code, I could be wrong.

while (true)
{
  UDTSOCKET recver = UDT::accept(serv, (sockaddr*)&their_addr, &namelen);

  cout << "new connection: " << inet_ntoa(their_addr.sin_addr) << ":" << ntohs(their_addr.sin_port) << endl;

  if (UDT::ERROR == UDT::recv(recver, data, 100, 0))
  {
    cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl;
    //return 0;
  }
....................
....................
}
Community
  • 1
  • 1
riderchap
  • 667
  • 2
  • 11
  • 19
1

Client and server structure doesn't match.

Client sends 10 times inside 1 connection. Server accepts 10 connections and reads only 1 time inside each one.

Obviously, each connection is simmilar to a container. Data sent but not read after closing a connection is discarded and (of course) not accessible from other connections.

Will
  • 11
  • 1