0
votes

This is my sending programm.

#pragma once
#pragma comment(lib,"Ws2_32.lib")

#include <WinSock2.h>
#include <Windows.h>
#include <iostream>

using namespace std;

int main()
{
    WSAData wsaData;
    WORD DllVersion = MAKEWORD(2,2);
    int startup_RetVal = WSAStartup(DllVersion, &wsaData);

    SOCKET sSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

    SOCKADDR_IN addr;

    addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    addr.sin_family = AF_INET;
    addr.sin_port = htons(22222);

    char buf[200000] = "AR*REF=";

    int send_RetVal = sendto(sSocket, buf, 200000, NULL, (SOCKADDR*)&addr, sizeof(addr));
    if(send_RetVal == SOCKET_ERROR)
    {
        cout <<" An error occured " << WSAGetLastError() << endl;
        getchar();
    }

    return 0;
}

I get a WSAEMSGSIZE (10040) error.

The goal is to send a 100Kbytes file over udp. I was told that similar error on .NET was solved this way :

IPHostEntry^ IPHostTV;

IPEndPoint^ send_tv_ip;

Socket^ UDPSendTV;

int PortSendTV;
System::String^ IPSend;



send_tv_ip =
gcnew IPEndPoint(IPHostTV->AddressList[0], PortSendTV);

UDPSendTV =
gcnew Socket(send_tv_ip->Address->AddressFamily, SocketType::Dgram, ProtocolType::Udp);

//Increasing buffer and timeout
UDPSendTV->SendTimeout = 1000;
UDPSendTV->SendBufferSize = 100000;

UDPSendTV->SendTo(buff1, 0, size1, SocketFlags::None, send_tv_ip);

How do I modify my sockets so they work correctly?

1

1 Answers

2
votes

The message size over UDP is limited by the protocol to ~64KB by the 16-bit message size field in the UDP header. There is no workaround.

(well, except for sending multiple messages per protocol unit).