本文整理汇总了C#中WebSocket4Net.WebSocket.Open方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocket.Open方法的具体用法?C# WebSocket.Open怎么用?C# WebSocket.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocket4Net.WebSocket
的用法示例。
在下文中一共展示了WebSocket.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChatHandler
public ChatHandler(RichTextBox messageList, RichTextBox roomMessageList)
{
this.messageList = messageList;
this.roomMessageList = roomMessageList;
websocket = new WebSocket("ws://" + ClientBase.serverAdress + PORT_ROUTE);
websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(receiveChat);
websocket.Open();
}
示例2: MainWindow
public MainWindow()
{
InitializeComponent();
if (serverURL == "")
{
textBox1.Text = "[エラー]";
textBox2.Text = "[エラー]\n";
textBox2.Text += " サーバのURLを講義担当者から聞いてserverURL変数にセットしてください\n";
}
else
{
websocket = new WebSocket(serverURL);
websocket.Closed += new EventHandler(websocket_Closed);
websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
websocket.Opened += new EventHandler(websocket_Opened);
textBox2.Text += "[使い方]\n";
textBox2.Text += " 上のテキストボックスに入力しenterか送信ボタンでサーバへ送信されます。\n";
textBox2.Text += " サーバは得たデータの先頭に'Server said'と付けて、そのまま返します。\n";
textBox2.Text += " サーバから帰って来た文字列がこのテキストボックスに表示されます。\n";
textBox2.Text += " 発言の先頭に「all:」を付けて送信すると、サーバに接続している全員に送られます。\n";
textBox2.Text += "[init]\n";
textBox1.Focus();
websocket.Open();
}
}
示例3: FetchConnections
public void FetchConnections()
{
if (!_isConnected)
throw new Exception("Not connected");
_socket = new WebSocket("wss://www.irccloud.com/", "", _cookies, null, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "https://www.irccloud.com");
_socket.MessageReceived += socket_MessageReceived;
_socket.Open();
}
示例4: Start
public void Start()
{
if (_ws != null) return;
string wsUrl;
if (!string.IsNullOrEmpty(_symbol))
{
wsUrl = string.Format("wss://www.stockfighter.io/ob/api/ws/{0}/venues/{1}/tickertape/stocks/{2}", _account, _venue, _symbol);
}
else
{
wsUrl = string.Format("wss://www.stockfighter.io/ob/api/ws/{0}/venues/{1}/tickertape", _account, _venue);
}
_ws = new WebSocket(wsUrl);
_ws.MessageReceived += MessageReceived;
_ws.Opened += (s, e) => { if (Started != null) Started(this, EventArgs.Empty); };
_ws.Error += (s, e) => { if (ErrorOccured != null) ErrorOccured(this, e.Exception.Message); };
_ws.Closed += (s, e) =>
{
if (Stopped != null) Stopped(this, EventArgs.Empty);
if (_reconnect) _ws.Open();
};
_ws.Open();
}
示例5: Connect
public void Connect()
{
String url;
if (String.IsNullOrEmpty(Port) ||
String.IsNullOrEmpty(Domain))
return;
url = String.Format("ws://{0}:{1}{2}", Domain, Port, Path);
try
{
socket = new WebSocket(
url,
"",
Cookies,
null,
null,
"http://" + Domain,
WebSocketVersion.DraftHybi10
);
socket.Opened += new EventHandler(socket_Opened);
socket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(socket_MessageReceived);
socket.Closed += new EventHandler(socket_Closed);
socket.Open();
}
catch (Exception e)
{
Debug.Print(String.Format("Websocket connection failed. {0} {1}", url, e.Message));
}
}
示例6: MainWindow
public MainWindow()
{
InitializeComponent();
if (serverURL == "")
{
textBox1.Text = "URL不明!";
}
else
{
textBox1.Text = channel;
websocket = new WebSocket(serverURL);
websocket.Closed += new EventHandler(websocket_Closed);
websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
websocket.Opened += new EventHandler(websocket_Opened);
websocket.Open();
InitializeComponent(); // aaa
//Kinectの初期化
kinect = KinectSensor.KinectSensors[0];
//イベントハンドラの登録
kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(handler_SkeletonFrameReady);
//骨格トラッキングの有効化
kinect.SkeletonStream.Enable();
kinect.Start(); // aaa
}
}
示例7: ReserveConnection
public static WebSocketDisposable ReserveConnection(string uri)
{
Tuple<WebSocket, RefCountDisposable> connection;
lock(openConnectionsLock)
{
if(!openConnections.TryGetValue(uri, out connection))
{
Debug.WriteLine("Creating new websocket");
WebSocket ws = new WebSocket(uri);
// Set callbacks?
ws.Open();
var dispose = Disposable.Create(() =>
{
Debug.WriteLine("Disposing of websocket");
ws.Close();
openConnections.Remove(uri);
});
RefCountDisposable refCount = new RefCountDisposable(dispose);
connection = Tuple.Create(ws, refCount);
openConnections.Add(uri, connection);
return new WebSocketDisposable(connection.Item1, connection.Item2.GetDisposable());
}
}
Debug.WriteLine("Returning old websocket");
return new WebSocketDisposable(connection.Item1, connection.Item2.GetDisposable());
}
示例8: Connect
void Connect(int times=3)
{
if (times > 0)
{
try
{
_socketInstance = new WebSocket(_serverAddress);
_socketInstance.Opened += _socketInstance_Opened;
_socketInstance.Closed += _socketInstance_Closed;
_socketInstance.DataReceived += _socketInstance_DataReceived;
_socketInstance.Error += _socketInstance_Error;
_socketInstance.Open();
}
catch (System.Exception e)
{
_dispatcher.LogException(e);
_dispatcher.LogWarning("Connect Failed! Try again 3 seconds later!");
Connect(times - 1);
}
}
else
{
_dispatcher.Quit();
}
}
示例9: OnlineUserHandler
//Object syncLock = new Object();
public OnlineUserHandler(ListView onlineUserList)
{
this.onlineUserList = onlineUserList;
websocket = new WebSocket("ws://" + ClientBase.serverAdress + PORT_ROUTE);
websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(handleOnlineUsers);
websocket.Open();
}
示例10: Connect
public void Connect(string url)
{
session_.Settings.ConnectionURI = url;
if (!url.Contains("ws://"))
url = "ws://" + url;
if (socket_ != null) {
if (session_ != null)
session_.IsConnected = false;
socket_.Close();
socket_ = null;
}
if (socket_ == null) {
session_.Log.Add(new LogMessage {
MsgType = MessageType.Info,
Message = "Attempting to connect"
});
string res = new Uri(url).AbsoluteUri;
socket_ = new WebSocket(res);
socket_.EnableAutoSendPing = true;
socket_.AutoSendPingInterval = 50;
socket_.Opened += _Opened;
socket_.Closed += _Closed;
socket_.MessageReceived += _ReceiveMsg;
socket_.DataReceived += _ReceiveData;
socket_.Error += _Error;
socket_.Open();
}
}
示例11: Connect
public void Connect(string url)
{
Uri uri = null;
string connectionId = Strings.RandomString(8);
int serverId = Strings.RandomNumber(1, 1000);
try
{
uri = new Uri(url);
}
catch (Exception)
{
throw new OrtcEmptyFieldException(String.Format("Invalid URL: {0}", url));
}
string prefix = uri != null && "https".Equals(uri.Scheme) ? "wss" : "ws";
Uri connectionUrl = new Uri(String.Format("{0}://{1}:{2}/broadcast/{3}/{4}/websocket", prefix, uri.DnsSafeHost, uri.Port, serverId, connectionId));
//
// NOTE: For wss connections, must have a valid installed certificate
// See: http://www.runcode.us/q/c-iphone-push-server
//
_websocket = new WebSocket(connectionUrl.AbsoluteUri);
_websocket.Opened += new EventHandler(websocket_Opened);
_websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
_websocket.Closed += new EventHandler(websocket_Closed);
_websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
_websocket.Open();
}
示例12: PingPong
public void PingPong()
{
using (NetMQContext context = NetMQContext.Create())
{
using (WebSocket4Net.WebSocket webSocket = new WebSocket("ws://localhost:82", "WSNetMQ"))
{
webSocket.EnableAutoSendPing = true;
webSocket.AutoSendPingInterval = 1; // one second
using (WSRouter router = context.CreateWSRouter())
{
router.Bind("ws://localhost:82");
ManualResetEvent manualResetEvent = new ManualResetEvent(false);
webSocket.Opened += (sender, args) => manualResetEvent.Set();
webSocket.Open();
webSocket.Error += (sender, args) => Console.WriteLine("Error");
manualResetEvent.WaitOne();
Thread.Sleep(5000);
Assert.AreEqual(webSocket.State, WebSocketState.Open);
}
}
}
}
示例13: Connect
public Task Connect(string host, CancellationToken cancelToken)
{
try
{
_webSocket = new WebSocketClient(host);
_webSocket.EnableAutoSendPing = false;
_webSocket.NoDelay = true;
_webSocket.Proxy = null;
_webSocket.DataReceived += OnWebSocketBinary;
_webSocket.MessageReceived += OnWebSocketText;
_webSocket.Error += OnWebSocketError;
_webSocket.Closed += OnWebSocketClosed;
_webSocket.Opened += OnWebSocketOpened;
_waitUntilConnect.Reset();
_waitUntilDisconnect.Reset();
_webSocket.Open();
_waitUntilConnect.Wait(cancelToken);
_taskManager.ThrowException(); //In case our connection failed
}
catch
{
_waitUntilDisconnect.Set();
throw;
}
return TaskHelper.CompletedTask;
}
示例14: Main
static void Main(string[] args)
{
m_WebSockets = new WebSocket[1000];
var autoEventReset = new AutoResetEvent(false);
for(var i = 0; i < m_WebSockets.Length; i++)
{
var websocket = new WebSocket("ws://localhost:2011/");
websocket.Opened += (s, e) =>
{
autoEventReset.Set();
};
websocket.Error += (s, e) =>
{
Console.WriteLine(e.Exception.Message);
autoEventReset.Set();
};
websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
websocket.Open();
autoEventReset.WaitOne();
m_WebSockets[i] = websocket;
Console.WriteLine(i);
}
Console.WriteLine("All connected");
Console.ReadLine();
}
示例15: MainWindow
public MainWindow()
{
InitializeComponent();
if (serverURL == "")
{
textBox1.Text = "URL不明!";
}
else
{
textBox1.Text = channel;
websocket = new WebSocket(serverURL);
websocket.Closed += new EventHandler(websocket_Closed);
websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
websocket.Opened += new EventHandler(websocket_Opened);
websocket.Open();
drumset = new Drumset();
drumset.SetElements(
new CircleTarget("RideCymbal", new Position3D(0.4, 0.3, 2.0), 0.3),
new CircleTarget("HiHat", new Position3D(-0.7, 0.1, 2.4), 0.3),
new CircleTarget("Drum1", new Position3D(-0.2, 0.0, 2.2), 0.3),
new CircleTarget("Drum2", new Position3D(0.5, 0.1, 2.6), 0.3)
);
System.Console.WriteLine("Loaded");
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
this.sensor = potentialSensor;
break;
}
}
if (null != this.sensor)
{
// Turn on the skeleton stream to receive skeleton frames
this.sensor.SkeletonStream.Enable();
// Add an event handler to be called whenever there is new color frame data
this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
// Start the sensor!
try
{
this.sensor.Start();
}
catch (IOException)
{
this.sensor = null;
}
}
this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
}
}