Dns









How do I use Dns
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PingCloudRegions.cs Copy
218     public static string ResolveHost(string hostName)
219     {
220         try
221         {
222             IPAddress[] address = Dns.GetHostAddresses(hostName);
223
224             if (address.Length == 1)
225             {
226                 return address[0].ToString();
227             }
228
229             // if we got more addresses, try to pick a IPv4 one
230             for (int index = 0; index < address.Length; index++)
231             {
232                 IPAddress ipAddress = address[index];
233                 if (ipAddress != null)
234                 {
235                     string ipString = ipAddress.ToString();
236                     if (ipString.IndexOf('.') >= 0)
237                     {
238                         return ipString;
239                     }
240                 }
241             }
242         }
243         catch (System.Exception e)
244         {
245             Debug.Log("Exception caught! " + e.Source + " Message: " + e.Message);
246         }
247
248         return String.Empty;
249     }
File name: SocketUdp.cs Copy
39         public override bool Connect()
40         {
41             lock (this.syncer)
42             {
43                 bool baseOk = base.Connect();
44                 if (!baseOk)
45                 {
46                     return false;
47                 }
48
49                 this.State = PhotonSocketState.Connecting;
50
51                 Thread dns = new Thread(this.DnsAndConnect);
52                 dns.Name = "photon dns thread";
53                 dns.IsBackground = true;
54                 dns.Start();
55
56                 return true;
57             }
58         }
File name: SocketUdp.cs Copy
119         internal void DnsAndConnect()
120         {
121             try
122             {
123                 lock (this.syncer)
124                 {
125                     this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
126
127                     IPAddress ep = IPhotonSocket.GetIpAddress(this.ServerAddress);
128                     this.sock.Connect(ep, this.ServerPort);
129
130                     this.State = PhotonSocketState.Connected;
131                 }
132             }
133             catch (SecurityException se)
134             {
135                 if (this.ReportDebugOfLevel(DebugLevel.ERROR))
136                 {
137                     this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() failed: " + se.ToString());
138                 }
139
140                 this.HandleException(StatusCode.SecurityExceptionOnConnect);
141                 return;
142             }
143             catch (Exception se)
144             {
145                 if (this.ReportDebugOfLevel(DebugLevel.ERROR))
146                 {
147                     this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() failed: " + se.ToString());
148                 }
149
150                 this.HandleException(StatusCode.ExceptionOnConnect);
151                 return;
152             }
153
154             Thread run = new Thread(new ThreadStart(ReceiveLoop));
155             run.Name = "photon receive thread";
156             run.IsBackground = true;
157             run.Start();
158         }

Download file with original file name:Dns

Dns 152 lượt xem

Gõ tìm kiếm nhanh...