- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
Latest commit
77 lines (71 loc) · 1.49 KB
/
Copy pathclient.cpp
File metadata and controls
77 lines (71 loc) · 1.49 KB
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
#include"client.h"
#include<sys/types.h>
#include<sys/socket.h>
#include<cstring>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<cstdio>
#include<cstdlib>
#include<netdb.h>
#include"network.h"
#include"utils.h"
Client::Client()
{
w = newMainWindow(0, this);
w->show();
connected = false;
}
int* Client::get_sock()
{
return &sock;
}
voidClient::set_hostname(QString s)
{
strcpy(hostname, convert_to_cstring((s)));
}
voidClient::set_username(QString s)
{
strcpy(username, convert_to_cstring((s)));
}
voidClient::set_port(QString s)
{
port = s.toInt();
}
boolClient::is_connected()
{
return connected;
}
voidClient::set_connect()
{
connected = true;
}
voidClient::send_data()
{
if(send(sock, message, BUFLEN, 0) == -1)
{
// error
}
}
voidClient::set_message(constchar *s)
{
strcpy(message, s);
}
intClient::connect_to_server()
{
structsockaddr_in server;
socklen_t serverlen = sizeof(server);
structhostent *hp;
if((sock = new_tcp_socket()) == -1)
{
// socket not created.
}
bzero((char *)&server, sizeof(structsockaddr_in));
server.sin_family = AF_INET;
server.sin_port = htons(port);
if((hp = gethostbyname(hostname)) == NULL)
{
// fatal("Unknown server address"); // maybe not have fatal? Can have client re enter the IP address.
}
bcopy(hp->h_addr, (char *)&server.sin_addr, hp->h_length);
returnconnect(sock, (structsockaddr*) &server, serverlen);
}