I want to create a wrapper over sockets in the form of 2 simple classes. Similar to QTUdp. http://doc.qt.io/qt-5/qudpsocket.html

But to create it, I need the working code of the client and server udp. Who has the WORKING code in mind (best through std :: .....) UPD: I need ASYNCHRONOUS input output.

What I found since the 90s and not even compiled. It would be desirable and on the code worked. Using boost is not acceptable! (Because it is installed for 2 hours and not even from 1 time).

Win compile VS and Linux QTCreator.

  • What does "UDP server" mean? What server exactly. UDP does not guarantee the delivery and order of delivery of packets, for this reason data is already placed inside the packets to ensure this. Those. make your application protocol over UDP, after which this protocol is implemented. And 95% of the whole code depends on the invented protocol and UDP doesn’t concern as such. Therefore, there can be no universal UDP server. As an example, take the code of any TFTP server and client. Oh, they are definitely compiled, because they work on a bunch of systems - Mike
  • This means that the working code of the echo server for example I know what UDP is. I do not need a ready-made server to preserve the task. I need a working code for the interaction of 2 applications over the network. - Nikita Samoukov
  • Well, this is written in 15 minutes. Ready to look for no particular need. almost the first thing that gives Google on request "udp echo" gist.github.com/suyash/0f100b1518334fcf650bbefd54556df9 looks quite working. Of course, when compiling on a specific system, there may be some features with data types and they will need to be corrected. - Mike
  • This code does not compile. - Nikita Samoukov
  • Then I have questions for your compiler. I immediately compile without even issuing a single warning, the errors are not visible either. I just made the file cli.c. I put the code in it and compiled gcc -O2 cli.c And yes, "not compiling" does not mean anything. could at least write with some errors. Better to read the mistakes yourself and correct them - Mike

1 answer 1

In most cases, when reworking simple Linux-based "socket projects" into Windows (such as this one https://gist.github.com/suyash/0f100b1518334fcf650bbefd54556df9 ), you need to do the following.

  • remove linux headers

     #include <arpa/inet.h> #include <netinet/in.h> 
  • add screw

     #include <winsock2.h> 
  • add libs Ws2_32.lib to the link or the next line in the code

     #pragma comment (lib, "Ws2_32.lib") 
  • if at compilation the compiler curses outdated functions of the form inet_ntoa , add define to the top

     #define _WINSOCK_DEPRECATED_NO_WARNINGS 
  • Do not forget to add a call iResult = WSAStartup(MAKEWORD(2,2), &wsaData); ( example ).

    (the server after that is at least compiled, launched and started)

  • No it's not enough. recvfrom does not accept sockaddr_in * - Nikita Samoukov
  • not compiled, falls, blue screen, pink? - KoVadim
  • Error error C3861: close: identifier not found Error error C3861: inet_pton: identifier not found - Nikita Samoukov
  • buffer [len] = '\ 0'; server compiled but crashed mk len = -1 - Nikita Samoukov
  • on some studios, it seems you need to add #include <ws2tcpip.h> . And close - this is from the client code - replace with closesocket. And the fact that he falls - well ... that's another matter. - KoVadim 1:51 pm