IEnumerator IsCanConnect(string url)
{
HttpWebRequest req = null;
HttpWebResponse res = null;
bool CanCn = true; //设成可以连接;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
res = (HttpWebResponse)req.GetResponse();
}
catch (Exception e)
{
Debug.Log(e.Message);
CanCn = false; //无法连接
_playStatus = PlayStatus.Error;
}
finally
{
if (res != null)
{
res.Close();
}
}
yield return new WaitForEndOfFrame();
}
IEnumerator IsCanConnect(string url)
{
//UnityWebRequest request = UnityWebRequest.Get(url);
UnityWebRequest request = new UnityWebRequest(url);
//
request.method = UnityWebRequest.kHttpVerbCREATE;
yield return request.SendWebRequest();
if (request.isNetworkError)
{
Debug.Log(request.error);
_playStatus = PlayStatus.Error;
}
else
{
}
}
IEnumerator PingHost(string Address, int TimeOut = 1000)
{
using (System.Net.NetworkInformation.Ping PingSender = new System.Net.NetworkInformation.Ping())
{
PingOptions Options = new PingOptions();
Options.DontFragment = true;
string Data = "test";
byte[] DataBuffer = System.Text.Encoding.ASCII.GetBytes(Data);
PingReply Reply = PingSender.Send(Address, TimeOut, DataBuffer, Options);
yield return Reply;
if (Reply.Status != IPStatus.Success)
{
_playStatus = PlayStatus.Error;
}
}
}
www下载
最新推荐文章于 2024-03-19 23:00:00 发布