-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
70 lines (59 loc) · 1.72 KB
/
client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#pragma comment(lib,"user32.lib")
#define PORT 3490
#define BUFFER_SIZE 1024
#define SERVER_IP "127.0.0.1"
int main() {
unsigned int width = 0, height = 0;
width = (int)GetSystemMetrics(SM_CXSCREEN);
height = (int)GetSystemMetrics(SM_CYSCREEN);
WSADATA wsa;
SOCKET client_socket;
struct sockaddr_in server_addr;
char buffer[BUFFER_SIZE] = {0};
char buf[BUFFER_SIZE] = {0};
int bytes = 0;
if (WSAStartup(MAKEWORD(2,2), &wsa) != 0) {
printf("Failed. Error Code : %d", WSAGetLastError());
return 1;
}
if ((client_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
printf("Could not create socket : %d", WSAGetLastError());
}
server_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
// Connect to server
if (connect(client_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
printf("Connect failed: %d", WSAGetLastError());
return 1;
}
POINT p;
while (1)
{
GetCursorPos(&p);
printf("x: %ld, y: %ld\n", p.x, p.y);
sprintf(buffer, "%ld,%ld", p.x, p.y);
send(client_socket, buffer, strlen(buffer), 0);
bytes = recv(client_socket, buf, 1024, 0);
if (bytes < 0)
{
printf("Error bytes received: %d\n", bytes);
exit(2);
}
// while (bytes == 0)
// bytes = recv(client_socket, buf, 1024, 0);
// printf("Server answer = %s\n", buf);
// Sleep(1000);
}
closesocket(client_socket);
WSACleanup();
return 0;
}