UnityでWebClientクラスをつかって文字列を取ってこようとしたときにMonoDevelopでデバッグしている状態ではなぜかタイムアウトが起こる。普通に動かす場合は特に問題ないみたい。
以下、エラーが出たコード。socket.ioのサーバにつなごうとしている。
using UnityEngine; using System.Collections; using System; using System.Net; public class Test : MonoBehaviour { void Start () { using(WebClient client = new WebClient()) { client.DownloadStringAsync(new Uri("http://localhost:3000/socket.io/1/&t=1112333333")); client.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) => { Debug.Log(e.Error); // -> System.Net.WebException: The request timed out Debug.Log(e.Result); }; } } }
とりあえずUnityのWWWクラスを使えば問題なさそう。原因はよく分からないけどもしかしたらsocket.ioのテスト環境が悪いのかもしれない。
広告
コメントを残す