Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #define _WINSOCK_DEPRECATED_NO_WARNINGS 1
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- #include <conio.h>
- #include <winsock.h>
- #include <locale>
- #include <sstream>
- #include <string>
- #include <conio.h>
- #include <math.h>
- #pragma comment(lib,"ws2_32.lib")
- #pragma pack (1)
- using namespace std;
- /*
- struct Pierwsza{
- unsigned short int punkty;
- int x[3];
- int y[3];
- int time[3];
- };
- struct Dane{
- //char kod;
- Pierwsza dane[1024];
- };
- */
- void ShowError(){
- char blad[1024];
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, WSAGetLastError(), 0, blad, sizeof(blad), NULL);
- printf("%s\n", blad);
- }
- int main()
- {
- setlocale(LC_ALL, "Polish");
- WSADATA ws;
- int blad = WSAStartup(MAKEWORD(2, 2), &ws);
- ShowError();
- SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- //Pierwsza dane1;
- if (s != SOCKET_ERROR)
- {
- sockaddr_in addr = { 0 };
- addr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
- addr.sin_family = AF_INET;
- addr.sin_port = htons(12345);
- char buffer[128];
- char odbior[128];
- char text[] = "exit";
- char bin[] = "bin";
- int addrSize = sizeof(addr);
- std::string kuniec;
- std::stringstream ss;
- cin >> buffer;
- sendto(s, buffer, strlen(buffer), 0, (sockaddr*)&addr, sizeof(addr));
- cout << "Wyslana wiadomosc to: " << buffer << endl;
- int n = recvfrom(s, buffer, sizeof(buffer), 0, (sockaddr*)&addr, &addrSize);\
- cout << "Odebrana wiadomosc to: " << buffer << endl;
- do
- {
- //std::cout << "wprowadz text" << std::endl;
- do
- {
- cin >> buffer;
- int n = sendto(s, buffer, strlen(buffer), 0, (sockaddr*)&addr, sizeof(addr));
- cout << "Wyslana wiadomosc to: " << buffer << endl;
- //ShowError();
- if (n > 0)
- {
- n = recvfrom(s, buffer, sizeof(buffer), 0, (sockaddr*)&addr, &addrSize);
- cout << "Odebrana wiadomosc to: " << buffer << endl;
- }
- std::cout << "skonczyc t/n?" << std::endl;
- }while(_stricmp(buffer,text) != 0);
- } while (kuniec.compare("tak"));
- closesocket(s);
- ShowError();
- }
- WSACleanup();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement