Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #define _CRT_SECURE_NO_WARNINGS
- #include <winsock.h>
- #include <time.h>
- #include <iostream>
- #pragma comment(lib, "Ws2_32.lib");
- #include "main.h"
- //192.168.16.165 send
- //192.168.16.170 accept
- using namespace std;
- SOCKET s;
- static bool b = false;
- int main()
- {
- WSADATA wsaData;
- WSAStartup(MAKEWORD(2, 2), &wsaData);
- s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (s < 0)
- {
- printf("error1 \n");
- system("pause");
- }
- sockaddr_in clientAddr;
- clientAddr.sin_family = AF_INET;
- clientAddr.sin_port = htons(3228);
- clientAddr.sin_addr.s_addr = inet_addr("192.168.16.165");
- sockaddr_in from;
- from.sin_family = AF_INET;
- from.sin_port = htons(3228);
- from.sin_addr.s_addr = htons(INADDR_ANY);
- int b = bind(s, (sockaddr *)&from, sizeof(from));
- int a = WSAGetLastError();
- printf("ws:%i\n", a);
- while (true)
- {
- int sSize = sizeof(from);
- char* recvp = new char[520];
- if (b == true)
- {
- int rm = recvfrom(s, recvp, 520, 0, (sockaddr*)&from, &sSize);
- if (rm < 0)
- {
- printf("norm\n");
- }
- printf("message: %s\n", recvp);
- }
- int a = 0;
- a = atoi(recvp);
- a++;
- sprintf(recvp, "%i", a);
- Sleep(500);
- int rp = sendto(s, recvp, sizeof(recvp), 0, (sockaddr*)&clientAddr, sizeof(clientAddr));
- if (rp < 0)
- {
- printf("cant send\n");
- system("pause");
- }
- b = true;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement