public int UdpReceiveFrom(EndPoint remoteEP, byte[] request, int requestOffset, int requestCount, byte[] response, int responseOffset = 0, int timeout = 10000) { switch (_type) { case NetProxyType.Socks5: if (_viaProxy != null) { throw new NotSupportedException("Cannot chain proxies for SOCKS5 Udp protocol."); } using (SocksUdpAssociateRequestHandler proxyUdpRequestHandler = _socksProxy.UdpAssociate(timeout)) { proxyUdpRequestHandler.ReceiveTimeout = timeout; //send request proxyUdpRequestHandler.SendTo(request, requestOffset, requestCount, remoteEP); //receive request return(proxyUdpRequestHandler.ReceiveFrom(response, responseOffset, response.Length - responseOffset, out EndPoint ep)); } default: throw new NotSupportedException("Proxy type not supported."); } }
public bool IsUdpAvailable() { if (_isUdpAvailableChecked) { return(_isUdpAvailable); } switch (_type) { case NetProxyType.Http: _isUdpAvailable = false; break; case NetProxyType.Socks5: SocksUdpAssociateRequestHandler udpHandler = null; try { udpHandler = _socksProxy.UdpAssociate(); _isUdpAvailable = true; } catch (SocksClientException ex) { if (ex.ReplyCode == SocksReplyCode.CommandNotSupported) { _isUdpAvailable = false; } else { throw; } } finally { if (udpHandler != null) { udpHandler.Dispose(); } } break; default: throw new NotSupportedException("Proxy type not supported."); } _isUdpAvailableChecked = true; return(_isUdpAvailable); }