-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathConnectionSocket.cpp
executable file
·95 lines (76 loc) · 2.31 KB
/
ConnectionSocket.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// This is the source code of Telegram for Windows Phone v. 3.x.x.
// It is licensed under GNU GPL v. 2 or later.
// You should have received a copy of the license in this archive (see LICENSE).
//
// Copyright Evgeny Nadymov, 2013-present.
//
#include "pch.h"
//#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include "ConnectionSocket.h"
#pragma comment(lib,"WS2_32")
using namespace TelegramClient_Native;
void ConnectionSocket::SendPacket(Platform::String^ caption, const Platform::Array<uint8>^ data)
{
}
void ConnectionSocket::Close()
{
int err = closesocket(_socket);
if (err < 0)
{
printf("closesocket failed with error: %d\n", err);
return;
}
}
ConnectionSocket::ConnectionSocket(Platform::String^ host, int port)
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
/* Tell the user that we could not find a usable */
/* Winsock DLL. */
printf("WSAStartup failed with error: %d\n", err);
return;
}
_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in serverAddr;
memset(&serverAddr, 0, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = inet_addr("149.154.175.50");
serverAddr.sin_port = htons(443);
err = connect(_socket, (sockaddr*)&serverAddr, sizeof(serverAddr));
if (err < 0)
{
printf("connect failed with error: %d\n", err);
return;
}
/*err = closesocket(_socket);
if (err < 0)
{
printf("closesocket failed with error: %d\n", err);
return;
}*/
//int sockbufsize = 0, size = sizeof(int);
//err = getsockopt(skt, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &size);
//WSACleanup();
}
int ConnectionSocket::GetReceiveBufferSize()
{
int sockbufsize = 0, size = sizeof(int);
int err = getsockopt(_socket, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &size);
return sockbufsize;
}
int ConnectionSocket::GetSendBufferSize()
{
int sockbufsize = 0, size = sizeof(int);
int err = getsockopt(_socket, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsize, &size);
return sockbufsize;
}