本文整理汇总了C#中WebSocket.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocket.Connect方法的具体用法?C# WebSocket.Connect怎么用?C# WebSocket.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocket
的用法示例。
在下文中一共展示了WebSocket.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
/// <summary>
/// Start the Birb Client.
/// </summary>
/// <returns>Nothing right now.</returns>
IEnumerator Start()
{
gameStateManager = GetComponent<GameStateManager>();
Uri server = new Uri("ws://birb.herokuapp.com");
Uri localhost = new Uri("ws://localhost:5000");
socket = new WebSocket(server);
callbacks = new Dictionary<BirbMessageCode, Callback>();
yield return StartCoroutine(socket.Connect());
int i = 0;
// Testing
//RunUnitTests();
while (true)
{
string reply = socket.RecvString();
if (reply != null)
{
Debug.Log("Received: " + reply);
Process(reply);
}
if (socket.Error != null)
{
Debug.LogError("Error: " + socket.Error);
break;
}
yield return 0;
}
socket.Close();
}
示例2: Connect
void Connect()
{
ws = new WebSocket("ws://socket.nappers.jp:8888");
// called when websocket messages come.
ws.OnMessage += (sender, e) =>
{
string s = e.Data;
Debug.Log(string.Format( "Receive {0}",s));
messages.Add("> " + e.Data);
if(messages.Count > 10){
messages.RemoveAt(0);
}
};
ws.OnError += (sender, e) =>
{
Debug.Log("OnError");
};
ws.OnClose += (sender, e) =>
{
Debug.Log("OnClose");
};
ws.OnOpen += (sender, e) =>
{
Debug.Log("OnOpen");
};
ws.Connect();
Debug.Log("Connect to " + ws.Url);
}
示例3: Start
// Use this for initialization
IEnumerator Start () {
WebSocket w = new WebSocket(new Uri("ws://127.0.0.1:8080/websocket"));
yield return StartCoroutine(w.Connect());
int i = 0;
w.SendString(PackMessage("Hi there", i));
while (true)
{
string reply = w.RecvString();
if (reply != null)
{
Message msg = UnpackMessage (reply);
Debug.Log ("Received: " + msg.msg + ", " + msg.no);
w.SendString (PackMessage ("Hi there", i));
}
if (w.error != null)
{
Debug.LogError ("Error: " + w.error);
break;
}
++i;
yield return 0;
}
w.Close();
}
示例4: InitWebSocket
void InitWebSocket()
{
_ws = new WebSocket ("wss://echo.websocket.org/");
_ws.OnMessage += MessageCallback;
_ws.OnError += ErrorCallback;
_ws.Connect ();
}
示例5: Connect
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
void Connect()
{
ws = new WebSocket (WSAddress);
ws.OnOpen += (sender, e) => {
Debug.Log ("<color=lime>WebSocket Open</color>");
};
ws.OnMessage += (sender, e) => {
lock (messageQueue.SyncRoot) {
try {
messageQueue.Enqueue (e.Data.ToString ());
} catch (System.Exception ex) {
Debug.Log (ex.ToString ());
}
}
//Debug.Log ("<color=cyan>WebSocket Message Type: " + e.Type + ", Data: " + e.Data + "</color>");
};
ws.OnError += (sender, e) => {
Debug.Log ("<color=red>WebSocket Error Message: " + e.Message + "</color>");
};
ws.OnClose += (sender, e) => {
Debug.Log ("<color=orange>WebSocket Close</color>");
};
ws.Connect ();
}
示例6: Play
public void Play()
{
var uri = new Uri(Server + "?user=" + Uri.EscapeDataString(UserName));
using (var socket = new WebSocket(uri))
{
socket.Connect();
while (!ShouldExit)
{
var response = socket.Recv();
if (!response.StartsWith(ResponsePrefix))
{
Console.WriteLine("Something strange is happening on the server... Response:\n{0}", response);
ShouldExit = true;
}
else
{
var boardString = response.Substring(ResponsePrefix.Length);
var action = DoMove(new GameBoard(boardString));
socket.Send(action);
}
}
}
}
示例7: Connect
void Connect()
{
//接続
//ポートの指定はしなくても大丈夫だった。80で接続してるはず。
ws = new WebSocket(url);
ws.OnOpen += (sender, e) => {
//接続したら自分を制御用PCとしてサーバーに教える
//SendSetPCMessage();
print("Connected");
};
ws.OnMessage += (sender, e) => {
string s = e.Data;
//Debug.Log (s);
Dictionary<string, object> dict = Json.Deserialize (s) as Dictionary<string, object>;
//Debug.Log (dict["power"].GetType() );
long val = (long)dict["power"];
//Debug.Log ("val="+val);
toColor = GetColor(val/divBy);
value = val/divBy;
};
ws.Connect();
ws.OnClose += (sender, e) => {
print("Closed");
};
ws.OnError += (sender, e) => {
print("Error : " + e.Message);
};
}
示例8: Start
IEnumerator Start()
{
_game = gameObject.GetComponent<MainProxy>();
_state = ConnectionState.UNKNOWN;
_socket = new WebSocket (new Uri ("ws://188.242.130.83:3000/echo"));
yield return StartCoroutine (_socket.Connect ());
}
示例9: WebtestClient
public WebtestClient(string port)
{
client = new WebSocket(@"ws://127.0.0.1:" + port + "/Simulator");
client.Connect();
client.OnError += (sender, e) =>
Debug.Log("error: " + e.Message.ToString());
client.OnClose += (sender, e) =>
Debug.Log("client on closing");
}
示例10: Connect
public void Connect(string playerName, string url)
{
PlayerName = playerName;
if (Socket != null)
Disconnect();
Socket = new WebSocket(new Uri(url));
StartCoroutine(Socket.Connect());
}
示例11: PongWebSockets
public PongWebSockets(string WebSocketServerAddress)
{
//nf = new Notifier();
ws = new WebSocket(WebSocketServerAddress);
ws.OnMessage += Ws_OnMessage;
ws.OnOpen += Ws_OnOpen;
ws.OnClose += Ws_OnClose;
ws.OnError += Ws_OnError;
ws.Connect();
}
示例12: Connect
void Connect()
{
ws = new WebSocket("ws://localhost:8888/");
// called when websocket messages come.
ws.OnMessage += (sender, e) =>
{
/*
string s = e.Data;
Debug.Log(string.Format( "Receive {0}",s));
messages.Add("> " + e.Data);
if(messages.Count > 10){
messages.RemoveAt(0);
}
*/
var jsonData = MiniJSON.Json.Deserialize(e.Data) as Dictionary<string,object>;
string message = (string)jsonData["message"];
if(message == "returnform")
{
//get Map Data
}
else if(message == "requestcreateform")
{
//createMap
}
else if(message == "returnscore")
{
// rannkinnguitiran
}
else if(message == "sendposition")
{
//anotherUserPosition
Debug.Log("a");
}
else if(message == "setuserid")
{
SetUserID((string)jsonData["userID"]);
}
Debug.Log(message);
};
ws.OnError += (sender, e) =>
{
Debug.Log("aa");
};
ws.OnClose += (sender, e) =>
{
Debug.Log("Closing...");
};
ws.Connect();
Debug.Log("Connect to " + ws.Url);
}
示例13: Start
// https://github.com/sta/websocket-sharp
void Start()
{
socket = new WebSocket("ws://literature.uncontext.com:80");
socket.OnError += (sender, e) => {
Debug.Log ("socket Error: " + e.Message.ToString());
};
socket.OnMessage += (sender, e) => {
Debug.Log ("socket message: " + e.Data);
};
socket.Connect();
}
示例14: Reconnect
public void Reconnect(string WebSocketServerAddress)
{
ws.Close();
ws.OnMessage -= Ws_OnMessage;
ws.OnOpen -= Ws_OnOpen;
ws.OnClose -= Ws_OnClose;
ws.OnError -= Ws_OnError;
ws = new WebSocket(WebSocketServerAddress);
ws.OnMessage += Ws_OnMessage;
ws.OnOpen += Ws_OnOpen;
ws.OnClose += Ws_OnClose;
ws.OnError += Ws_OnError;
ws.Connect();
}
示例15: ListenToMtgox
private static void ListenToMtgox()
{
var ws = new WebSocket("ws://" + Dns.GetHostAddresses("websocket.mtgox.com").First().ToString() + ":80/mtgox", "*");
var observableWs = new ObservableWebsocket(ws);
if (!ws.Connect())
{
Console.WriteLine("Not connected");
Console.ReadLine();
}
else
{
Console.Clear();
Connected(observableWs);
ws.Close();
}
}