本文整理匯總了C#中Quobject.SocketIoClientDotNet.Client.Socket.Open方法的典型用法代碼示例。如果您正苦於以下問題:C# Socket.Open方法的具體用法?C# Socket.Open怎麽用?C# Socket.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Quobject.SocketIoClientDotNet.Client.Socket
的用法示例。
在下文中一共展示了Socket.Open方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: connectSocket
public void connectSocket()
{
if (this.TOKEN != null)
{
try
{
Dictionary<string, string> _author = new Dictionary<string, string>();
_author.Add("token", this.TOKEN);
IO.Options _option = new IO.Options();
//_option.Timeout = 5000;
_option.Query = _author;
_option.ForceNew = true;
_option.Reconnection = true;
_option.ReconnectionDelay = 500;
mSocket = IO.Socket(HOSTNAME, _option);
mSocket.On(Socket.EVENT_CONNECT, () =>
{
Dispatcher dispatcher = Deployment.Current.Dispatcher;
dispatcher.BeginInvoke(() =>
{
// MessageBox.Show("OK");
});
Debug.WriteLine("OK");
});
mSocket.On(Socket.EVENT_CONNECT_ERROR, onConnectError);
mSocket.On(Socket.EVENT_CONNECT_TIMEOUT, onConnectTimeout);
mSocket.On(Socket.EVENT_ERROR, () =>
{
Dispatcher dispatcher = Deployment.Current.Dispatcher;
dispatcher.BeginInvoke(() =>
{
// MessageBox.Show("ERROR");
mSocket.Connect();
mSocket.Open();
});
});
mSocket.On(Constant.SOCKET_EVENT_JOIN, onJoinRoom);
mSocket.On(Constant.SOCKET_EVENT_ADD, onAddUser);
mSocket.On(Constant.SOCKET_EVENT_LEAVE, onLeaveRoom);
mSocket.On(Constant.SOCKET_EVENT_CHANGE_ROOM_TITLE, onChangeRoomTitle);
mSocket.On(Constant.SOCKET_EVENT_CHAT, (data) => {
Debug.WriteLine(data.ToString());
Dispatcher dispatcher = Deployment.Current.Dispatcher;
dispatcher.BeginInvoke(() =>
{
String result = data.ToString();
ChatResponse resultObject = JsonConvert.DeserializeObject<ChatResponse>(result);
if(resultObject.data.message.type == 2)
{
App.ViewModel.Items.Add(new ViewModels.ItemViewModel() { SenderID = resultObject.data.sender._id, CreateAt = resultObject.data.sequence, MessageText = resultObject.data.message.message, Avatar = new Uri(resultObject.data.sender.avatar), Type = resultObject.data.message.type, thumbnail = new Uri(resultObject.data.message.file.thumbnail, UriKind.RelativeOrAbsolute) });
}
else
{
App.ViewModel.Items.Add(new ViewModels.ItemViewModel() { SenderID = resultObject.data.sender._id, CreateAt = resultObject.data.sequence, MessageText = resultObject.data.message.message, Avatar = new Uri(resultObject.data.sender.avatar), Type = resultObject.data.message.type });
}
if(resultObject.data.sender._id != App._userid)
{
var stream = Application.GetResourceStream(new Uri(@"Assets/Audio/recieve.wav", UriKind.RelativeOrAbsolute));
var effect = SoundEffect.FromStream(stream.Stream);
var soundInstance = effect.CreateInstance();
FrameworkDispatcher.Update();
soundInstance.Play();
App._reuserid = resultObject.data.sender._id;
ToastPrompt tost = new ToastPrompt()
{
Title = resultObject.data.sender.username,
Message = resultObject.data.message.message,
};
tost.Tap += tosk_Tap;
tost.Show();
}
});
});
mSocket.Connect();
}
catch(Exception e)
{
Debug.WriteLine("IO exception " + e.Message);
//mSocket.Close();
// mSocket.Open();
}
}
else
{
Debug.WriteLine("No token found!");
}
}