Transfer through WinSock a mass(unsigned int buf[20];



  • Hi, there's a problem, I can't get the data on the sketch, that's unsigned int. Runs 39 lines, says,

    [C++ Error] KlientUDP.cpp(39): E2034 Cannot convert 'unsigned int *' to 'const char *'
    [C++ Error] KlientUDP.cpp(39): E2342 Type mismatch in parameter 'buf' (wanted 'const char *', got 'unsigned int *')
    

    Character's moving without a problem, and it doesn't work. Please help me find mistakes, so the sockets have met recently, maybe something major I don't know. Well, I'll be glad to see each answer.

    Here's Client's code.

    //---------------------------------------------------------------------------
    

    #include <vcl.h>
    #pragma hdrstop

    #include "KlientUDP.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent
    Owner)
    : TForm(Owner)
    {
    const int iReqWinsockVer = 2;
    WSADATA wsaData;

        if (WSAStartup(iReqWinsockVer,&amp;wsaData)==0)
        {
                ShowMessage("Инициализация библиотеки сокета(Ws2_32.dll) удалась");
                SOCKET s;
                s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    
                if (s == INVALID_SOCKET)
                        ShowMessage("При создании сокета возникла ошибка");
                else
                        ShowMessage("Создание сокета было успешным!");
    
                sockaddr_in sockAddr;
                sockAddr.sin_family = AF_INET;
                sockAddr.sin_port = htons(80);
                sockAddr.sin_addr.S_un.S_addr = inet_addr("169.254.128.135");
    
                unsigned int buf[20];
                buf[0] = 3;
    
                while(true)
                {
                        sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&amp;sockAddr, sizeof(sockAddr));
                }
    
                closesocket(s);
    
                if (WSACleanup()!=0)
                        ShowMessage("Освобождение ресурсов WinSock не удалось");
                else
                        ShowMessage("Освобождение ресурсов WinSock завершилось успехом");
        }
        else
                ShowMessage("Инициализация библиотеки сокета(Ws2_32.dll) не удалась");
    

    }



  • sendto Acceptance const char*What's inside is he doesn't care if the dimensions match, so:

    sendto(s, (const char*)buf, sizeof(buf), 0, (struct sockaddr *)&sockAddr, sizeof(sockAddr));
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2