Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "stdafx.h"
- #include <locale.h>
- #include <WinSock2.h>
- #include <conio.h>
- #pragma comment(lib, "Ws2_32.lib")
- void CheckErrorByCode(int code)
- {
- char Buff[1024];
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, code, NULL, Buff, sizeof(Buff), NULL);
- printf(" %s", Buff);
- }
- int main(int argc, char** argv) {
- setlocale(LC_ALL, "Polish");
- WSADATA wsa;
- SOCKADDR_IN addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons(19390);
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- char BuffToSend2[] = "Editable";
- char BuffToShow2[2048];
- char Host[512];
- int result = WSAStartup(MAKEWORD(2, 0), &wsa);
- if (result != 1)
- {
- printf("WSAStartup initialization: ");
- CheckErrorByCode(result);
- }
- else
- {
- printf("WSAStartup initialization error! Error code: %d", result);
- CheckErrorByCode(result);
- }
- result = gethostname(Host, sizeof(Host));
- if (result == 1)
- {
- printf("Get hostname function error! Error code: %d", result);
- CheckErrorByCode(result);
- }
- SOCKET Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- bind(Socket, (SOCKADDR*)&addr, sizeof(addr));
- for (int i = 0; i < 2048; i++)
- {
- BuffToShow2[i] = NULL;
- }
- int AddrSize = sizeof(addr);
- recvfrom(Socket, BuffToShow2, sizeof(BuffToShow2), 0, (SOCKADDR*)&addr, &AddrSize);
- int len = strlen(BuffToShow2);
- strncat(BuffToSend2,BuffToShow2,strlen(BuffToShow2));
- sendto(Socket, BuffToSend2, strlen(BuffToSend2), 0, (SOCKADDR*)&addr, sizeof(addr));
- closesocket(Socket);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement