private static void StartClient() { // Connect to a remote device. try { _streemData = new StreemData(); client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); //client.ExclusiveAddressUse = false; //IPAddress localip1 = IPAddress.Parse(localIP); IPEndPoint ipep = new IPEndPoint(IPAddress.Any, _dataPort); client.Bind(ipep); IPAddress ip = IPAddress.Parse(_multicastIPAddress); client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any)); /* * //initialize command socket * mCommandListner = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); * mCommandListner.Bind(new IPEndPoint(IPAddress.Any, 0)); * * //set socket to boradcast mode * mCommandListner.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); * * mCommandListner.Blocking = false; * mCommandListner.ReceiveBufferSize = SOCKET_BUFSIZE; * * PACKET_FORMAT packet = new PACKET_FORMAT(); * packet.header.iMessage = NAT_REQUEST_MODELDEF; * packet.header.nDataBytes = 0; * byte[] msg = new byte[4]; * IntPtr ptr = Marshal.AllocHGlobal(4); * Marshal.StructureToPtr(packet, ptr, true); * Marshal.Copy(ptr, msg, 0, 4); * mCommandListner.SendTo(msg, mRemoteIpEndPoint); * Marshal.FreeHGlobal(ptr); * * Receive(mCommandListner); */ _isInitRecieveStatus = Receive(client); _isIsActiveThread = _isInitRecieveStatus; } catch (Exception e) { Debug.LogError("[UDP] DirectMulticastSocketClient: " + e.ToString()); } }
private static void StartClient() { // Connect to a remote device. try { _streemData = new StreemData(); client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); //client.ExclusiveAddressUse = false; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, _dataPort); client.Bind(ipep); IPAddress ip = IPAddress.Parse(_multicastIPAddress); client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any)); _isInitRecieveStatus = Receive(client); _isIsActiveThread = _isInitRecieveStatus; } catch (Exception e) { Debug.LogError("[UDP] DirectMulticastSocketClient: " + e.ToString()); } }