Documentation of SFML 1.6

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
SocketUDP.hpp
1 
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef SFML_SOCKETUDP_HPP
26 #define SFML_SOCKETUDP_HPP
27 
29 // Headers
31 #include <SFML/Network/SocketHelper.hpp>
32 #include <vector>
33 
34 
35 namespace sf
36 {
37 class Packet;
38 class IPAddress;
39 template <typename> class Selector;
40 
45 class SFML_API SocketUDP
46 {
47 public :
48 
53  SocketUDP();
54 
62  void SetBlocking(bool Blocking);
63 
72  bool Bind(unsigned short Port);
73 
80  bool Unbind();
81 
93  Socket::Status Send(const char* Data, std::size_t Size, const IPAddress& Address, unsigned short Port);
94 
108  Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address, unsigned short& Port);
109 
120  Socket::Status Send(Packet& PacketToSend, const IPAddress& Address, unsigned short Port);
121 
133  Socket::Status Receive(Packet& PacketToReceive, IPAddress& Address, unsigned short& Port);
134 
141  bool Close();
142 
150  bool IsValid() const;
151 
158  unsigned short GetPort() const;
159 
168  bool operator ==(const SocketUDP& Other) const;
169 
178  bool operator !=(const SocketUDP& Other) const;
179 
190  bool operator <(const SocketUDP& Other) const;
191 
192 private :
193 
194  friend class Selector<SocketUDP>;
195 
203  SocketUDP(SocketHelper::SocketType Descriptor);
204 
211  void Create(SocketHelper::SocketType Descriptor = 0);
212 
214  // Member data
216  SocketHelper::SocketType mySocket;
217  unsigned short myPort;
218  Uint32 myPendingHeader;
219  Uint32 myPendingHeaderSize;
220  std::vector<char> myPendingPacket;
221  Int32 myPendingPacketSize;
222  bool myIsBlocking;
223 };
224 
225 } // namespace sf
226 
227 
228 #endif // SFML_SOCKETUDP_HPP