本文整理匯總了C#中WebSocketSharp.WebSocket.ConnectAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# WebSocket.ConnectAsync方法的具體用法?C# WebSocket.ConnectAsync怎麽用?C# WebSocket.ConnectAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WebSocketSharp.WebSocket
的用法示例。
在下文中一共展示了WebSocket.ConnectAsync方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Start
void Start() {
ws = new WebSocket("ws://echo.websocket.org");
ws.OnOpen += OnOpenHandler;
ws.OnMessage += OnMessageHandler;
ws.OnClose += OnCloseHandler;
stateMachine.AddHandler(State.Running, () => {
new Wait(this, 3, () => {
ws.ConnectAsync();
});
});
stateMachine.AddHandler(State.Connected, () => {
stateMachine.Transition(State.Ping);
});
stateMachine.AddHandler(State.Ping, () => {
new Wait(this, 3, () => {
ws.SendAsync("This WebSockets stuff is a breeze!", OnSendComplete);
});
});
stateMachine.AddHandler(State.Pong, () => {
new Wait(this, 3, () => {
ws.CloseAsync();
});
});
stateMachine.Run();
}
示例2: NetworkInterface
public NetworkInterface(string address, ContentManager c)
{
sock = new WebSocket(address);
Content = c;
connected = false;
sock.OnMessage += (sender, e) =>
{
byte[] r = e.RawData;
string s = System.Text.Encoding.UTF8.GetString(r);
doNetworkInput(s);
};
sock.OnOpen += (sender, e) =>
{
connected = true;
Console.WriteLine("Connected");
onReady();
};
sock.OnClose += (sender, e) =>
{
Console.WriteLine("Ran onclose");
connected = false;
};
sock.OnError += (sender, e) =>
{
if (e.Message == "An error has occurred while connecting.")
{
connected = false;
onReady();
}
};
sock.ConnectAsync();
}
示例3: Start
void Start() {
ws = new WebSocket("ws://echo.websocket.org");
ws.OnOpen += OnOpenHandler;
ws.OnMessage += OnMessageHandler;
ws.OnClose += OnCloseHandler;
ws.ConnectAsync();
}
示例4: Start
// Use this for initialization
void Start()
{
ws = new WebSocket(serverIp);
ws.OnOpen += OnOpenHandler;
ws.OnMessage += OnMessageHandler;
ws.OnClose += OnCloseHandler;
ws.ConnectAsync();
}
示例5: Start
void Start () {
// Retrieve the main camera
mainCam = Camera.main;
// Create and Open the websocket
ws = new WebSocket("ws://"+ GatewayIP + ":" + WebsocketPort);
ws.OnOpen += OnOpenHandler;
ws.OnMessage += OnMessageHandler;
ws.OnClose += OnCloseHandler;
ws.ConnectAsync();
}
示例6: start
public void start() {
webSocketClient = new WebSocket(url);
webSocketClient.OnError += new EventHandler<WebSocketSharp.ErrorEventArgs>(webSocketClient_Error);
webSocketClient.OnOpen += new EventHandler(webSocketClient_Opened);
webSocketClient.OnClose += new EventHandler<WebSocketSharp.CloseEventArgs>(webSocketClient_Closed);
webSocketClient.OnMessage += new EventHandler<MessageEventArgs>(webSocketClient_MessageReceived);
webSocketClient.ConnectAsync();
while (!webSocketClient.IsAlive) {
Console.WriteLine("Waiting WebSocket connnet......");
Thread.Sleep(1000);
}
t.Elapsed += new System.Timers.ElapsedEventHandler(heatBeat);
t.Start();
}
示例7: Connect
internal void Connect()
{
// TODO: Handle and test disconnection / errors etc
// TODO: Add 'connecting_in' event
ChangeState(ConnectionState.Connecting);
_allowReconnect = true;
_websocket = new WebSocket(_url);
_websocket.OnError += websocket_Error;
_websocket.OnOpen += websocket_Opened;
_websocket.OnClose += websocket_Closed;
_websocket.OnMessage += websocket_MessageReceived;
_websocket.ConnectAsync();
}
示例8: Start
void Start()
{
toSend = new JSONClass();
N = JSONNode.Parse("{\"op\": \"advertise\",\"topic\": \"helloString\",\"type\": \"std_msgs/String\"}");
toSend["op"] = "publish";
toSend["topic"] = "helloString";
data = new JSONClass();
data["data"] = "Why Hello there ros, Fancy meeting you here.";
toSend["msg"] = data;
ws = new WebSocket("ws://localhost:9090");
ws.OnOpen += OnOpenHandler;
ws.OnMessage += OnMessageHandler;
ws.OnClose += OnCloseHandler;
ws.ConnectAsync();
}
示例9: NetworkInterface
public NetworkInterface(string address, ContentManager c)
{
Console.WriteLine("Hello");
bufferedMap = new List<string>();
bufferedPlayers = new List<string>();
messagesReceived = 0;
sock = new WebSocket(address);
game = null;
Content = c;
connected = false;
mapLoaded = false;
roomNumber = -1;
sock.OnMessage += (sender, e) =>
{
byte[] r = e.RawData;
string s = System.Text.Encoding.UTF8.GetString(r);
doNetworkInput(s);
};
sock.OnOpen += (sender, e) =>
{
connected = true;
startTime = DateTime.Now;
Console.WriteLine("Connected");
};
sock.OnClose += (sender, e) =>
{
Console.WriteLine("Ran onclose");
connected = false;
mapLoaded = false;
};
sock.OnError += (sender, e) =>
{
if (e.Message == "An error has occurred while connecting.")
{
connected = false;
generateMap();
onReady();
}
};
sock.ConnectAsync();
}
示例10: Connect
public Task<bool> Connect()
{
var tcs = new TaskCompletionSource<bool>();
_webSocket = new WebSocket("ws://127.0.0.1:{0}/debugger-proxy".ToFormat(Port));
_webSocket.OnOpen += async (sender, args) =>
{
System.Diagnostics.Debug.WriteLine("WS: Opened");
await PrepareJSRuntime();
tcs.TrySetResult(true);
};
_webSocket.OnClose += (sender, args) =>
{
System.Diagnostics.Debug.WriteLine("WS: Closed");
};
_webSocket.OnMessage += (sender, args) =>
{
HandleJson(args.Data);
};
_webSocket.ConnectAsync();
return tcs.Task;
}
示例11: Connect
public void Connect(string host)
{
this.host = host;
if(websocket != null)
{
Debug.LogWarning("Replacing existing websocket");
}
websocket = new WebSocket(host);
websocket.Log.Output = this.LogDelegate;
if (debugMode)
{
Debug.Log("Connecting to " + host);
websocket.Log.Level = LogLevel.Trace;
}
websocket.OnOpen += this.Open;
websocket.OnClose += this.Close;
websocket.OnMessage += this.Message;
websocket.OnError += this.Error;
websocket.ConnectAsync();
}
示例12: Connect
public IEnumerator Connect()
{
m_Socket = new WebSocketSharp.WebSocket(mUrl.ToString(), new string[] { "GpBinaryV16" });// modified by TS
m_Socket.OnMessage += (sender, e) => m_Messages.Enqueue (e.RawData);
m_Socket.OnOpen += (sender, e) => m_IsConnected = true;
m_Socket.OnError += (sender, e) => m_Error = e.Message + (e.Exception == null ? "" : " / "+ e.Exception);
m_Socket.ConnectAsync();
while (!m_IsConnected && m_Error == null)
yield return 0;
}
示例13: Connect
private void Connect() {
if(_ws!=null) {
if(_ws.IsAlive) {
_ws.Close(CloseStatusCode.Normal);
}
_ws=null;
}
if(_st==State.BadAuth) {
return;
}
if(_uri.IsDefaultPort) {
_host=string.Concat(_uri.Scheme, "://", _uri.DnsSafeHost);
} else {
_host=string.Concat(_uri.Scheme, "://", _uri.DnsSafeHost, ":", _uri.Port.ToString());
}
_remotePath=_uri.AbsolutePath+_uri.Fragment;
{
int i;
i=_remotePath.IndexOf("/#");
if(i<0) {
i=_remotePath.IndexOf("/+");
}
if(i>0) {
_remoteBase=_remotePath.Substring(0, i);
} else {
_remoteBase=_remotePath;
}
}
var up=Uri.UnescapeDataString(_uri.UserInfo).Split(':');
_uName=up.Length>0?up[0]:string.Empty;
_uPass=up.Length==2?up[1]:string.Empty;
_ws=new WebSocket(_host+"/api/v03");
_ws.Log.Output=WsLog;
_ws.OnOpen+=_ws_OnOpen;
_ws.OnMessage+=_ws_OnMessage;
_ws.OnError+=_ws_OnError;
_ws.OnClose+=_ws_OnClose;
_ws.ConnectAsync();
_reconn.Change(_rccnt * 15000, _rccnt * 30000);
}
示例14: PreStart
protected override void PreStart()
{
var self = Self;
_socket = new WebSocket(_endpoint);
_socket.OnOpen += (sender, args) =>
{
self.Tell(new ConnectionOpened());
};
_socket.OnMessage += (sender, args) =>
{
self.Tell(new MessageReceived(args));
};
_socket.OnError += (sender, args) =>
{
self.Tell(new ErrorOccurred(args.Message, args.Exception));
};
_socket.OnClose += (sender, args) =>
{
self.Tell(new ConnectionClosed());
};
_socket.SetCookie(new Cookie("ClientId", _clientId));
_socket.ConnectAsync();
}
示例15: SocketConnect
private IEnumerator SocketConnect(SocketKey key)
{
var url = componentModel.getComponentWSURL(key.componentName);
if (string.IsNullOrEmpty(url))
{
debug.LogError("Could not find url to open socket for component " + key.componentName, key);
yield return null;
}
var ws = new WebSocket(url);
sockets[key] = ws;
ws.WaitTime = new TimeSpan(0, 0, 5);
ws.OnMessage += (o, e) => onSocketMessage(key, o, e);
ws.OnError += (o, e) => onSocketError(key, o, e);
ws.OnOpen += (o, e) => onSocketOpen(key, o, e);
ws.OnClose += (o, e) => onSocketClose(key, o, e);
debug.Log("Attempting connection to " + url, key);
ws.ConnectAsync();
int i = 0;
while (i < 1000)
{
i++;
if (ws.ReadyState == WebSocketState.Open) break;
yield return null;
}
}