summaryrefslogtreecommitdiff
path: root/Runtime/Network/MulticastSocket.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Network/MulticastSocket.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Network/MulticastSocket.h')
-rw-r--r--Runtime/Network/MulticastSocket.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/Runtime/Network/MulticastSocket.h b/Runtime/Network/MulticastSocket.h
new file mode 100644
index 0000000..0b99d60
--- /dev/null
+++ b/Runtime/Network/MulticastSocket.h
@@ -0,0 +1,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