本文整理汇总了C#中WebSocketSharp.WebSocket.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocket.Connect方法的具体用法?C# WebSocket.Connect怎么用?C# WebSocket.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocketSharp.WebSocket
的用法示例。
在下文中一共展示了WebSocket.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScarletMetrics
/* WS */
public ScarletMetrics()
{
metricsws = new WebSocket("ws://" + MetricsWSURL + ":" + MetricsWSPort);
metricsws.Connect();
metricsws.OnOpen += (sender, e) =>
{
// Metrics - On Connection to the Metrics WS Reporting Server
// Need to include username / IP in here as well.
JsonObject jsonMessage = new JsonObject()
.add("type", "metrics")
.add("message", "connected");
metricsws.Send(jsonMessage.ToString());
};
metricsws.OnMessage += (sender, e) =>
{
};
metricsws.OnClose += (sender, e ) =>
metricsws.Connect();
metricsws.OnError += (sender, e) =>
metricsws.Connect();
}
示例2: ChatController
//needs to implemented from API
/// <summary>
///
/// </summary>
/// <param name="MessageReceived"></param>
public ChatController(Model m)
{
ws = new WebSocket("ws://127.0.0.1:8005/chat");
ws.OnMessage += (s, e) => GotPacket(e.Data);
ws.Connect();
this.m = m;
}
示例3: ThisAddIn_Startup
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Excel.Worksheet activeWorksheet = ((Excel.Worksheet)Application.ActiveSheet);
Excel.Range firstRow = activeWorksheet.get_Range("A1");
firstRow.EntireRow.Insert(Excel.XlInsertShiftDirection.xlShiftDown);
Excel.Range newFirstRow = activeWorksheet.get_Range("A1");
newFirstRow.Value2 = "lETS START THIS THING";
//lets start this thing
using (var ws = new WebSocket("ws://dumbsocket.herokuapp.com"))
{
ws.OnError += (error_sender, error_e) => {
Console.Write("socket error");
//SOME BROKE SHIT
};
ws.OnOpen += (open_sender, open_e) => {
Console.Write("sockets open");
//windows open
};
ws.OnClose += (close_sender, close_e) => {
Console.Write("socket closed");
};
ws.OnMessage += (socket_sender, socket_e) =>
{
newFirstRow.Value2 = "This is coming from the websocket" + socket_e.Data;
};
ws.Connect();
}
}
示例4: Main
public static void Main(string[] args)
{
if (args.Length != 1) {
Console.Error.WriteLine ("ERROR: need a valid Websocket URL");
Environment.Exit (-1);
}
using (var ws = new WebSocket (args[0])) {
Int64 syncCtr = 0;
ws.OnMessage += (sender, e) => {
Console.WriteLine (e.Data);
Interlocked.Decrement (ref syncCtr);
};
ws.Connect ();
if (!ws.IsAlive) {
Console.Error.WriteLine ("ERROR: Could not connect to Websocket Server {0}", args[0]);
Environment.Exit(-2);
}
var input = "";
while (string.Compare (input.Trim (), "shutdown", true) != 0) {
if (!string.IsNullOrWhiteSpace (input)) {
ws.Send (input.Trim());
Interlocked.Increment (ref syncCtr);
while (Interlocked.Read (ref syncCtr) > 0) {
Thread.Sleep (1);
}
}
Console.Write ("Type in a message or 'shutdown' to quit: ");
input = Console.ReadLine ();
} // Longevity loop
} // using
}
示例5: Start
public void Start(string address, int port, string path)
{
// IPAddress ipaddr = new IPAddress(address.Split('.').Select(a => (byte)a.to_i()).ToArray());
// WebSocketServer wss = new WebSocketServer(ipaddr, port, this);
wsc = new WebSocket(address + ":"+port+path, this);
wsc.OnMessage += OnMessage;
wsc.Connect();
}
示例6: StartWebSocket
private void StartWebSocket ()
{
webSocket = new WebSocket (wsUri.AbsoluteUri);
webSocket.Connect ();
webSocket.OnOpen += WebSocket_OnOpen;
webSocket.OnMessage += WebSocket_OnMessage;
webSocket.OnClose += WebSocket_OnClose;
webSocket.OnError += WebSocket_OnError;
}
示例7: button1_Click
private void button1_Click(object sender, EventArgs e)
{
ws = new WebSocket("ws://localhost:8080/?id=" + txtName.Text);
ws.OnOpen += new EventHandler(ws_OnOpen);
ws.OnMessage += new EventHandler<MessageEventArgs>(ws_OnMessage);
ws.OnError += new EventHandler<ErrorEventArgs>(ws_OnError);
ws.OnClose += new EventHandler<CloseEventArgs>(ws_OnClose);
ws.Connect();
}
示例8: ConnectWebSocket
public void ConnectWebSocket(string Address)
{
Socket = new WebSocket(Address, "connection");
Socket.OnOpen += ServerToClientConnected;
Socket.OnMessage += ServerToClientOnMessage;
Socket.OnClose += ServerToClientDisconnected;
Socket.Connect();
}
示例9: Main
public static void Main(string[] args)
{
//using (WebSocket ws = new WebSocket("ws://localhost:8000/"))
using (WebSocket ws = new WebSocket("ws://localhost:8000/", "chat"))
{
/*ws.OnOpen += (o, e) =>
{
//Do something.
};
*/
ws.OnMessage += (o, s) =>
{
#if NOTIFY
Notification nf = new Notification("[WebSocket] Message",
s,
"notification-message-im");
nf.AddHint("append", "allowed");
nf.Show();
#else
Console.WriteLine("[WebSocket] Message: {0}", s);
#endif
};
ws.OnError += (o, s) =>
{
Console.WriteLine("[WebSocket] Error : {0}", s);
};
/*ws.OnClose += (o, e) =>
{
//Do something.
};
*/
ws.Connect();
Thread.Sleep(500);
Console.WriteLine("\nType \"exit\" to exit.\n");
string data;
while (true)
{
Thread.Sleep(500);
Console.Write("> ");
data = Console.ReadLine();
if (data == "exit")
{
break;
}
ws.Send(data);
}
}
}
示例10: TestClient
static void TestClient()
{
using (var ws = new WebSocket("ws://localhost:8080/test1"))
{
ws.OnMessage += (sender, e) =>
Console.WriteLine("Laputa says: " + e.Data);
ws.Connect();
ws.Send("BALUS");
Console.ReadKey(true);
}
}
示例11: Connect
public bool Connect(string url, string session)
{
socket = new WebSocket(url);
socket.WaitTime = TimeSpan.FromSeconds(5);
socket.OnOpen += Socket_OnOpen;
socket.OnError += Socket_OnError;
socket.OnMessage += Socket_OnMessage;
socket.OnClose += Socket_OnClose;
socket.Connect();
reset.WaitOne();
return IsConnected;
}
示例12: OpenClient
public void OpenClient()
{
if (_client != null)
{
_client.OnMessage -= OnRecievedMessage;
_client.OnError -= OnError;
_client.Close();
}
_client = new WebSocket(Settings.Default.Url);
_client.OnMessage += OnRecievedMessage;
_client.OnError += OnError;
_client.Connect();
}
示例13: InternalConnect
public static void InternalConnect(String ipAddress)
{
try
{
webClient = new WebSocket("wss://" + ipAddress + ":3001");
webClient.OnMessage += webClient_OnMessage;
webClient.Connect();
}
catch (Exception ex)
{
Log.Error("Auto3D: " + ex.Message);
}
}
示例14: Connect
private void Connect(string url)
{
if (_webSocket != null)
{
_webSocket.Close();
_webSocket.OnMessage -= OnSocketMessage;
_webSocket.OnClose -= OnSocketClose;
_webSocket = null;
}
_webSocket = new WebSocket(url);
_webSocket.OnMessage += OnSocketMessage;
_webSocket.OnClose += OnSocketClose;
_webSocket.Connect();
}
示例15: WebSocketSharpServer
public WebSocketSharpServer(ServerSettings settings) {
Settings = settings;
Server = new WebSocketServer(Settings.Port);
BaseUri = new Uri($"ws://localhost:{Server.Port}");
Server.Start();
Server.AddWebSocketService<Heartbeat>($"/{HeartbeatEndpoint}");
Heartbeat = new WebSocket($"{BaseUri}{HeartbeatEndpoint}");
Heartbeat.Connect();
Task.Factory.StartNew(() => {
while (!_isDisposing) {
Heartbeat.Send("Heartbeat OK");
Task.Delay(5000).Wait();
}
});
}