IPAddress
How do I use I P Address
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
222 | IPAddress[] address = Dns.GetHostAddresses(hostName); | 1 |
127 | IPAddress ep = IPhotonSocket.GetIpAddress(this.ServerAddress); | 2 |
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
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:IPAddress
IPAddress 182 lượt xem
Gõ tìm kiếm nhanh...