YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
ClientSocket.cpp
Go to the documentation of this file.
1
#include <SFML/Network/IpAddress.hpp>
2
3
#include "
YAPOG/System/Network/ClientSocket.hpp
"
4
#include "
YAPOG/System/Network/IPacket.hpp
"
5
6
namespace
yap
7
{
8
const
bool
ClientSocket::DEFAULT_BLOCKING_STATE
=
false
;
9
const
Time
ClientSocket::DEFAULT_CONNECTION_TIMEOUT
= Time (3.0f);
10
11
ClientSocket::ClientSocket
()
12
:
Socket
()
13
,
socket_
()
14
{
15
socket_
.setBlocking (
DEFAULT_BLOCKING_STATE
);
16
}
17
18
ClientSocket::~ClientSocket
()
19
{
20
}
21
22
bool
ClientSocket::Connect
(
const
String
& ipAddress,
UInt16
port)
23
{
24
socket_
.setBlocking (
true
);
25
26
if
(
socket_
.connect (
27
sf::IpAddress (ipAddress),
28
port,
29
sf::seconds (
30
DEFAULT_CONNECTION_TIMEOUT
.
GetValue
())) != sf::Socket::Done)
31
return
false
;
32
33
socket_
.setBlocking (
DEFAULT_BLOCKING_STATE
);
34
35
return
true
;
36
}
37
38
void
ClientSocket::Disconnect
()
39
{
40
socket_
.disconnect ();
41
}
42
43
bool
ClientSocket::Send
(
IPacket
& packet)
44
{
45
return
socket_
.send (packet.
GetInnerPacket
()) == sf::Socket::Done;
46
}
47
48
bool
ClientSocket::Receive
(
IPacket
& packet)
49
{
50
return
socket_
.receive (packet.
GetInnerPacket
()) == sf::Socket::Done;
51
}
52
53
String
ClientSocket::GetRemoteAddress
()
const
54
{
55
return
socket_
.getRemoteAddress ().toString ();
56
}
57
58
UInt16
ClientSocket::GetRemotePort
()
const
59
{
60
return
socket_
.getRemotePort ();
61
}
62
63
sf::TcpSocket&
ClientSocket::GetInnerSocket
()
64
{
65
return
socket_
;
66
}
67
}
// namespace yap
YAPOG
src
YAPOG
System
Network
ClientSocket.cpp
Generated on Mon Sep 17 2012 22:24:26 for YAPOG by
1.8.1.1