{"record":{"id":"629b09ca25724fc7","repo":"egametang/ET","slug":"bind-error-ipendpoint","errorCode":null,"errorMessage":"bind error: {ipEndPoint}","messagePattern":"bind error: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Network/IKcpTransport.cs","lineNumber":45,"sourceCode":"            NetworkHelper.SetSioUdpConnReset(this.socket);\n        }\n        \n        public UdpTransport(IPEndPoint ipEndPoint)\n        {\n            this.socket = new Socket(ipEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);\n            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))\n            {\n                this.socket.SendBufferSize = Kcp.OneM * 64;\n                this.socket.ReceiveBufferSize = Kcp.OneM * 64;\n            }\n            \n            try\n            {\n                this.socket.Bind(ipEndPoint);\n            }\n            catch (Exception e)\n            {\n                throw new Exception($\"bind error: {ipEndPoint}\", e);\n            }\n\n            NetworkHelper.SetSioUdpConnReset(this.socket);\n        }\n        \n        public void Send(byte[] bytes, int index, int length, EndPoint endPoint, ChannelType channelType)\n        {\n            this.socket.SendTo(bytes, index, length, SocketFlags.None, endPoint);\n        }\n        \n        public int Recv(byte[] buffer, ref EndPoint endPoint)\n        {\n            return this.socket.ReceiveFrom(buffer, ref endPoint);\n        }\n\n        public IPEndPoint GetBindPoint()\n        {\n            return this.socket.LocalEndPoint as IPEndPoint;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Network/IKcpTransport.cs#L27-L63","documentation":"IKcpTransport constructor binds a UDP socket to ipEndPoint and wraps any Bind failure. UDP bind can fail for the same reasons TCP can: port in use, address not assigned to a host, or insufficient privileges for low ports.","triggerScenarios":"Two services binding the same UDP port, binding to an IP not present on the machine, or binding a port <1024 as non-root on Linux.","commonSituations":"Process restarted while the old socket is still in TIME_WAIT / held, misconfigured outer IP, or another instance already running.","solutions":["Free the port: stop the other process or let the OS release it (SO_REUSEADDR if your OS path allows).","Bind to a local IP that exists (use IPAddress.Any or a confirmed interface address).","Use an unprivileged port (>=1024) or run with elevated privileges.","Read the wrapped inner SocketException for the exact socket error code."],"exampleFix":"// before\nthis.socket.Bind(ipEndPoint);\n// after\nvar local = ipEndPoint.Address.Equals(IPAddress.Any) ? ipEndPoint : ipEndPoint;\nthis.socket.Bind(local); // ensure local.Address is assigned to this host","handlingStrategy":"try-catch","validationCode":"static bool IsPortFreeUDP(IPEndPoint ep)\n{\n    try { using var s = new Socket(ep.AddressFamily, SocketType.Dgram, ProtocolType.Udp); s.Bind(ep); return true; }\n    catch { return false; }\n}","typeGuard":"null","tryCatchPattern":"try { transport = new KcpTransport(ipEndPoint); }\ncatch (Exception e) when (e.Message.StartsWith(\"bind error\"))\n{ Log.Error($\"udp bind failed for {ipEndPoint}: {e.InnerException?.Message}\"); throw; }","preventionTips":["Probe the port before binding at startup.","Run only one instance per configured UDP port.","Use local interface addresses you have verified exist."],"tags":["network","kcp","udp","socket","csharp"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}