blob: 0b99d602f82587ec126405f71b800725e370325c (
plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#ifndef MULTICASTSOCKET_H
#define MULTICASTSOCKET_H
#if ENABLE_SOCKETS
#include "Sockets.h"
#if UNITY_WINRT
namespace UnityPlayer
{
[Windows::Foundation::Metadata::WebHostHidden]
public ref class MulticastSocketContext sealed
{
public:
MulticastSocketContext( Windows::Networking::HostName^ host, Platform::String^ port );
void OnSocketMessageReceived( Windows::Networking::Sockets::DatagramSocket^ dagSocket, Windows::Networking::Sockets::DatagramSocketMessageReceivedEventArgs^ args);
Windows::Networking::Sockets::DatagramSocket^ GetSocket() { return dagSocket; }
void Bind();
void Send(const Platform::Array<byte>^ dataToSend);
void SetLoop(bool loop);
private:
Windows::Networking::Sockets::DatagramSocket^ dagSocket;
Windows::Networking::HostName^ hostName;
Platform::String^ portNumber;
bool isLoopingBroadcast;
};
}
#endif // UNITY_WINRT
class MulticastSocket : protected Socket
{
public:
MulticastSocket();
bool Initialize(const char* group, unsigned short port, bool block = false);
bool Join();
bool Disband();
bool SetBroadcast(bool broadcast);
bool SetTTL(unsigned char ttl);
bool SetLoop(bool loop);
int Send(const void* data, size_t data_len);
int Recv(void* data, size_t data_len, RecvUserData* userData = NULL);
private:
#if UNITY_EDITOR
bool SetOptionForAllAddresses(int option, const char* msg = NULL);
#endif
bool m_Bound;
struct sockaddr_in m_MulticastAddress;
#if UNITY_WINRT
UnityPlayer::MulticastSocketContext^ m_context;
bool m_initalised;
#endif
};
#endif
#endif
|