CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
udp_client.h
1
2#pragma once
3
4#include <system/string.h>
5#include <system/shared_ptr.h>
6#include <system/object.h>
7#include <system/idisposable.h>
8#include <system/iasyncresult.h>
9#include <system/async_callback.h>
10#include <system/array.h>
11#include <net/sockets/socket.h>
12#include <net/sockets/address_family.h>
13#include <net/ip_end_point.h>
14#include <net/ip_address.h>
15#include <cstdint>
16
17namespace System { namespace Net { namespace Sockets {
18
23class ASPOSECPP_SHARED_CLASS UdpClient : public System::IDisposable
24{
26 typedef UdpClient ThisType;
29
31 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
33 ASPOSECPP_SHARED_RTTI_INFO_DECL();
34
35public:
38 ASPOSECPP_SHARED_API System::SharedPtr<Socket> get_Client();
41 ASPOSECPP_SHARED_API void set_Client(System::SharedPtr<Socket> value);
42 /*
43 ASPOSECPP_SHARED_API int32_t get_Available();
44 ASPOSECPP_SHARED_API int16_t get_Ttl();
45 ASPOSECPP_SHARED_API void set_Ttl(int16_t value);
46 ASPOSECPP_SHARED_API bool get_DontFragment();
47 ASPOSECPP_SHARED_API void set_DontFragment(bool value);
48 ASPOSECPP_SHARED_API bool get_MulticastLoopback();
49 ASPOSECPP_SHARED_API void set_MulticastLoopback(bool value);
50 ASPOSECPP_SHARED_API bool get_EnableBroadcast();
51 ASPOSECPP_SHARED_API void set_EnableBroadcast(bool value);
52 ASPOSECPP_SHARED_API bool get_ExclusiveAddressUse();
53 ASPOSECPP_SHARED_API void set_ExclusiveAddressUse(bool value);
54 */
55
57 ASPOSECPP_SHARED_API UdpClient();
60 ASPOSECPP_SHARED_API UdpClient(AddressFamily family);
63 ASPOSECPP_SHARED_API UdpClient(int32_t port);
67 ASPOSECPP_SHARED_API UdpClient(int32_t port, AddressFamily family);
70 ASPOSECPP_SHARED_API UdpClient(System::SharedPtr<IPEndPoint> localEP);
75 ASPOSECPP_SHARED_API UdpClient(String hostname, int32_t port);
77 ASPOSECPP_SHARED_API void Close();
79 ASPOSECPP_SHARED_API void Dispose() override;
83 ASPOSECPP_SHARED_API void Connect(String hostname, int32_t port);
87 ASPOSECPP_SHARED_API void Connect(System::SharedPtr<IPAddress> addr, int32_t port);
90 ASPOSECPP_SHARED_API void Connect(System::SharedPtr<IPEndPoint> endPoint);
91
97 ASPOSECPP_SHARED_API int32_t Send(System::ArrayPtr<uint8_t> dgram, int32_t bytes,
105 ASPOSECPP_SHARED_API int32_t Send(System::ArrayPtr<uint8_t> dgram, int32_t bytes, String hostname, int32_t port);
110 ASPOSECPP_SHARED_API int32_t Send(System::ArrayPtr<uint8_t> dgram, int32_t bytes);
111
116
117protected:
120 ASPOSECPP_SHARED_API bool get_Active();
123 ASPOSECPP_SHARED_API void set_Active(bool value);
126 ASPOSECPP_SHARED_API virtual void Dispose(bool disposing);
128 ASPOSECPP_SHARED_API ~UdpClient() override;
129
130private:
132 static const int32_t MaxUDPSize;
134 System::SharedPtr<Socket> m_ClientSocket;
136 bool m_Active;
140 AddressFamily m_Family;
142 bool m_CleanedUp;
144 bool m_IsBroadcast;
145
147 void FreeResources();
151 void CheckForBroadcast(System::SharedPtr<IPAddress> ipAddress);
155 static bool IsBroadcast(System::SharedPtr<IPAddress> address);
157 void createClientSocket();
158};
159
160}}} // namespace System::Net::Sockets
Defines method that releases resources owned by the current object. Objects of this class should only...
Definition: idisposable.h:30
Provides User Datagram Protocol (UDP) network services. Objects of this class should only be allocate...
Definition: udp_client.h:24
UdpClient(String hostname, int32_t port)
Creates a new instance of the UdpClient class and connects to the specified remote host on the specif...
UdpClient(AddressFamily family)
Initializes a new instance of the UdpClient class.
UdpClient(int32_t port)
Initializes a new instance of the UdpClient class.
bool get_Active()
Gets a value that indicates if the current instance is actively listening for the client connections.
void Dispose() override
Releases the managed and unmanaged resources used by the UdpClient.
UdpClient(int32_t port, AddressFamily family)
Initializes a new instance of the UdpClient class.
void Connect(String hostname, int32_t port)
Establishes a connection to the specified port on the specified host.
int32_t Send(System::ArrayPtr< uint8_t > dgram, int32_t bytes)
Sends a UDP datagram to a remote host.
int32_t Send(System::ArrayPtr< uint8_t > dgram, int32_t bytes, System::SharedPtr< IPEndPoint > endPoint)
Sends a UDP datagram to the host at the remote end point.
void set_Active(bool value)
Sets a value that indicates if the current instance is actively listening for the client connections.
void Close()
Closes the UDP connection.
int32_t Send(System::ArrayPtr< uint8_t > dgram, int32_t bytes, String hostname, int32_t port)
Sends a UDP datagram to the specified port on the specified remote host.
void set_Client(System::SharedPtr< Socket > value)
Used to provide the underlying network socket.
~UdpClient() override
Destructs the current instance.
System::ArrayPtr< uint8_t > Receive(System::SharedPtr< IPEndPoint > &remoteEP)
Returns a datagram sent by a server.
virtual void Dispose(bool disposing)
Disposes the current instance. This method also disposes the underlying socket.
System::SharedPtr< Socket > get_Client()
Used to provide the underlying network socket.
void Connect(System::SharedPtr< IPAddress > addr, int32_t port)
Establishes a connection with the host at the specified address on the specified port.
UdpClient()
Initializes a new instance of the UdpClient class.
UdpClient(System::SharedPtr< IPEndPoint > localEP)
Initializes a new instance of the UdpClient class. param local EP the local endpoint to which you bin...
void Connect(System::SharedPtr< IPEndPoint > endPoint)
Establishes a connection to a remote end point.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
AddressFamily
Enumerates the address families.
Definition: address_family.h:12
Definition: db_command.h:9