A game about forced loneliness, made by TACStudios
1/*--------------------------------------------------------------------------------------------- 2 * Copyright (c) Microsoft Corporation. All rights reserved. 3 * Licensed under the MIT License. See License.txt in the project root for license information. 4 *--------------------------------------------------------------------------------------------*/ 5using System; 6using System.Net; 7using System.Net.Sockets; 8 9namespace Microsoft.Unity.VisualStudio.Editor.Messaging 10{ 11 internal class UdpSocket : Socket 12 { 13 // Maximum UDP payload is 65507 bytes. 14 // TCP mode will be used when the payload is bigger than this BufferSize 15 public const int BufferSize = 1024 * 8; 16 17 internal UdpSocket() 18 : base(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) 19 { 20 SetIOControl(); 21 } 22 23 public void Bind(IPAddress address, int port = 0) 24 { 25 Bind(new IPEndPoint(address ?? IPAddress.Any, port)); 26 } 27 28 private void SetIOControl() 29 { 30#if UNITY_EDITOR_WIN 31 try 32 { 33 const int SIO_UDP_CONNRESET = -1744830452; 34 35 IOControl(SIO_UDP_CONNRESET, new byte[] { 0 }, new byte[0]); 36 } 37 catch 38 { 39 // fallback 40 } 41#endif 42 } 43 44 public static byte[] BufferFor(IAsyncResult result) 45 { 46 return (byte[])result.AsyncState; 47 } 48 49 public static EndPoint Any() 50 { 51 return new IPEndPoint(IPAddress.Any, 0); 52 } 53 } 54}