Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CLIENT UDP
- #define _WINSOCK_DEPRECATED_NO_WARNINGS
- #pragma comment(lib, "ws2_32.lib")
- #ifndef UNICODE
- #define UNICODE
- #endif
- #define WIN32_LEAN_AND_MEAN
- #include <WinSock2.h>
- #include <iostream>
- #include <WS2tcpip.h>
- #include <stdio.h>
- using namespace std;
- int main() {
- WSAData wsaData;
- WORD DLLVersion = MAKEWORD(2, 2);
- if (WSAStartup(DLLVersion, &wsaData) != 0)
- {
- MessageBoxA(NULL, "Start Winsocka zostal przerwany.", "Error", MB_OK | MB_ICONERROR);
- exit(1);
- }
- SOCKET SendSocket = INVALID_SOCKET;
- SOCKADDR_IN RecvAddr;
- SendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (SendSocket == INVALID_SOCKET) {
- cout << "Blad polaczenia..." << endl;
- exit(1);
- }
- RecvAddr.sin_family = AF_INET;
- RecvAddr.sin_port = htons(27015);
- RecvAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
- cout << "Przesylam..." << endl;
- int addrlen = sizeof(RecvAddr);
- int L;
- unsigned NetL;
- char Mess[10];
- cout << "Podaj liczbe: " << endl;
- cin >> L;
- std::cout << std::endl;
- NetL = htonl((unsigned)L);
- sendto(SendSocket, (char*)&NetL, sizeof(int), 0, (SOCKADDR *)& RecvAddr, sizeof(RecvAddr)); //wysylanie
- while (recvfrom(SendSocket, (char*)&Mess, sizeof(Mess), 0, (SOCKADDR *)& RecvAddr, &addrlen) > 0) {
- cout << Mess << endl;
- Sleep(2000);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement