YAPOG  0.0.1
Yet Another Pokemon Online Game
ClientSocket.cpp
Go to the documentation of this file.
1 #include <SFML/Network/IpAddress.hpp>
2 
5 
6 namespace yap
7 {
8  const bool ClientSocket::DEFAULT_BLOCKING_STATE = false;
9  const Time ClientSocket::DEFAULT_CONNECTION_TIMEOUT = Time (3.0f);
10 
12  : Socket ()
13  , socket_ ()
14  {
15  socket_.setBlocking (DEFAULT_BLOCKING_STATE);
16  }
17 
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 
39  {
40  socket_.disconnect ();
41  }
42 
43  bool ClientSocket::Send (IPacket& packet)
44  {
45  return socket_.send (packet.GetInnerPacket ()) == sf::Socket::Done;
46  }
47 
49  {
50  return socket_.receive (packet.GetInnerPacket ()) == sf::Socket::Done;
51  }
52 
54  {
55  return socket_.getRemoteAddress ().toString ();
56  }
57 
59  {
60  return socket_.getRemotePort ();
61  }
62 
63  sf::TcpSocket& ClientSocket::GetInnerSocket ()
64  {
65  return socket_;
66  }
67 } // namespace yap