if (WebRequest.DefaultWebProxy.GetProxy(new System.Uri("https://www.o-survey.com/")).ToString() == "https://www.o-survey.com/") { // A proxy is not in use here MessageBox.Show("A proxy is not in use here"); } else { MessageBox.Show("A proxy is in use"); // A proxy is in use } const int PORT = 6588; IPAddress IP; IPAddress.TryParse("192.168.1.240", out IP); // This constructor arbitrarily assigns the local port number. UdpClient udpClient = new UdpClient(PORT); Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); try { udpClient.Connect("192.168.1.240", PORT); if (udpClient.Client.Connected) // Sends a message to the host to which you have connected. Byte[] sendBytes = Encoding.ASCII.GetBytes("CONNECT"); udpClient.Send(sendBytes, sendBytes.Length); //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint RemoteIpEndPoint = new IPEndPoint(IP, PORT); // Blocks until a message returns on this socket from a remote host. Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); // Uses the IPEndPoint object to determine which of these two hosts responded. MessageBox.Show("This is the message you received " + returnData.ToString()); MessageBox.Show("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString()); System.Uri Url = new System.Uri("https://www.o-survey.com/"); System.Net.WebRequest WebReq; System.Net.WebResponse Resp; WebReq = System.Net.WebRequest.Create(Url); try { Resp = WebReq.GetResponse(); Resp.Close(); WebReq = null; MessageBox.Show("connected"); } catch { WebReq = null; MessageBox.Show("not connected"); } udpClient.Close(); } catch (Exception e) { MessageBox.Show(e.ToString()); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)