-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPconnection.cpp
More file actions
42 lines (37 loc) · 1022 Bytes
/
TCPconnection.cpp
File metadata and controls
42 lines (37 loc) · 1022 Bytes
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
#include "TCPconnection.h"
#include <iostream>
TCPconnection::TCPconnection(void)
{
}
TCPconnection::~TCPconnection(void)
{
}
void TCPconnection::connectWithSocket(sf::IpAddress &ip, sf::Packet &samplesP, sf::Packet &infosP)
{
if(connection.connect(ip, 53000) != sf::Socket::Done)
return;
if(connection.send(samplesP) != sf::Socket::Done)
return;
if(connection.send(infosP) != sf::Socket::Done)
return;
connection.disconnect();
}
bool TCPconnection::waitForConnections()
{
if(listener.listen(53000) != sf::Socket::Done)
return false;
if(listener.accept(connection) != sf::Socket::Done)
return false;
sf::Packet samplePacket, infoPacket;
if(connection.receive(samplePacket) != sf::Socket::Done)
return false;
if(connection.receive(infoPacket) != sf::Socket::Done)
return false;
recievedPackets[0] = samplePacket;
recievedPackets[1] = infoPacket;
player.processPackets(recievedPackets[0], recievedPackets[1]);
listener.close();
connection.disconnect();
waitForConnections();
return true;
}