本文整理匯總了C#中Quobject.SocketIoClientDotNet.Client.Socket.Emit方法的典型用法代碼示例。如果您正苦於以下問題:C# Socket.Emit方法的具體用法?C# Socket.Emit怎麽用?C# Socket.Emit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Quobject.SocketIoClientDotNet.Client.Socket
的用法示例。
在下文中一共展示了Socket.Emit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: NewGame
void NewGame()
{
string ten = name.Text;
if (canvas.Children.Count != 0)
canvas.Children.Clear();
game = new GomokuViewModel();
game.Paint_ChessBoard(canvas);
// mở kết nối
if (online)
{
socket = IO.Socket(Settings.Default.connectStr);
socket.On(Socket.EVENT_CONNECT, () =>
{
MessageBox.Show( "Connected");
socket.Emit("ChatMessage", "hh");
socket.Emit("message:" + "hh", "from:" + "hello");
});
socket.On(Socket.EVENT_MESSAGE, (data) =>
{
MessageBox.Show(((JObject)data)["message"].ToString());
});
socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
{
MessageBox.Show(((JObject)data)["message"].ToString());
});
socket.On("ChatMessage", (data) =>
{
if (((JObject)data)["message"].ToString() == "Welcome!")
{
socket.Emit("MyNameIs", ten);
socket.Emit("ConnectToOtherPlayer");
}
// nhận chat
if (data.ToString().Contains("from"))
{
MessageBox.Show(data.ToString());
}
});
socket.On(Socket.EVENT_ERROR, (data) =>
{
MessageBox.Show(((JObject)data)["message"].ToString());
});
socket.On("NextStepIs", (data) =>
{
MessageBox.Show(data.ToString());
});
}
}
示例2: MessageTest
public void MessageTest()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var count = new[] {0};
var events = new Queue<object>();
var options = CreateOptions();
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On(Socket.EVENT_CONNECT, () =>
{
log.Info("EVENT_CONNECT");
socket.Emit("hi");
});
socket.On("hi",
(data) =>
{
log.Info("EVENT_MESSAGE");
events.Enqueue(data);
ManualResetEvent.Set();
});
//socket.Open();
ManualResetEvent.WaitOne();
socket.Close();
var obj = events.Dequeue();
Assert.AreEqual("more data", (string) obj);
}
示例3: OgsMessageTest
public void OgsMessageTest()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var events = new Queue<object>();
var options = CreateOptions();
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On(Socket.EVENT_CONNECT, () =>
{
log.Info("EVENT_CONNECT");
socket.Emit("parser_error#21");
});
socket.On("parser_error#21_response",
(data) =>
{
log.Info("EVENT_MESSAGE");
events.Enqueue(data);
ManualResetEvent.Set();
});
//socket.Open();
ManualResetEvent.WaitOne();
socket.Close();
var obj = events.Dequeue();
Assert.Equal("{\"handicap\":0,\"disable_analysis\":false,\"private\":false,\"height\":19,\"time_control\":{\"time_control\":\"byoyomi\",\"period_time\":45,\"main_time\":1800,\"periods\":5},\"ranked\":false,\"meta_groups\":[132,3,196,261,327,489,43,418,302,463,242,403,425,24,25,154,28,157],\"komi\":6.5,\"game_id\":1333070,\"width\":19,\"rules\":\"japanese\",\"black_player_id\":71283,\"white_player_id\":78080,\"players\":{\"white\":{\"username\":\"Rvzy\",\"egf\":501.413,\"rank\":14,\"id\":78080,\"accepted_stones\":\"mcidkdldmdiekeefgfifkfdgegfghgkgfhghhhihkhnhfigihikinifjhjjjkjnjdkekfkgkhkjknkflhljlgmhmimjmgnknlnmnnngo\",\"accepted_strict_seki_mode\":false},\"black\":{\"username\":\"心の光\",\"egf\":353.454,\"rank\":12,\"id\":71283,\"accepted_stones\":\"mcidkdldmdiekeefgfifkfdgegfghgkgfhghhhihkhnhfigihikinifjhjjjkjnjdkekfkgkhkjknkflhljlgmhmimjmgnknlnmnnngo\",\"accepted_strict_seki_mode\":false}},\"game_name\":\"Friendly Match\",\"phase\":\"finished\",\"history\":[],\"initial_player\":\"black\",\"moves\":\"pddpppddfqfocqdjcpcodqepeqncqfkcfcgdcccddcfdecgcgbhbfahcbdbebccfpjnpqnjphphoioipgohngngphqfpgmilcndnbocmdoengqeocodlgkijhiiihhjgifighghfhkikekejfjelflfihjgihminimjnjmkmjlkljkkkjjliihjikjljkijhkhlgkgjfiejegfheidickfmekejdhllhfgehegdhfhedghffeffedgcgdkckfkcibmclblbkldlcmdndmcmbkdjcaeafadnfknjolnlplkllmkmmmnnmnnnkmjnjminimhnhmglfnlomolonmloonglmiqjqjrkrirmfofpbqcorproqpqopplpmqmpoqoosqppsqrqsrrrsoeneodwO6obqblaocnbpaoaqaksjsakalhafbsssr....\",\"allow_self_capture\":false,\"automatic_stone_removal\":false,\"free_handicap_placement\":false,\"allow_ko\":false,\"allow_superko\":true,\"superko_algorithm\":\"ssk\",\"score_territory\":true,\"score_territory_in_seki\":false,\"score_stones\":false,\"score_prisoners\":true,\"score_passes\":true,\"white_must_pass_last\":false,\"opponent_plays_first_after_resume\":true,\"strict_seki_mode\":false,\"initial_state\":{\"black\":\"\",\"white\":\"\"},\"start_time\":1420522348,\"clock\":{\"game_id\":1333070,\"current_player\":78080,\"black_player_id\":71283,\"white_player_id\":78080,\"title\":\"Friendly Match\",\"last_move\":1420524830517,\"expiration\":1420525270589,\"black_time\":{\"thinking_time\":909.8829999999991,\"periods\":5,\"period_time\":45},\"white_time\":{\"thinking_time\":215.07199999999966,\"periods\":5,\"period_time\":45},\"pause_delta\":-517,\"expiration_delta\":440072,\"now\":1420524830517,\"paused_since\":1420524830},\"pause_control\":{\"stone-removal\":true},\"paused_since\":1420524830,\"removed\":\"mcidkdldmdiekeefgfifkfdgegfghgkgfhghhhihkhnhfigihikinifjhjjjkjnjdkekfkgkhkjknkflhljlgmhmimjmgnknlnmnnngo\",\"auto_scoring_done\":true,\"score\":{\"white\":{\"total\":154.5,\"stones\":0,\"territory\":101,\"prisoners\":47,\"scoring_positions\":\"iajakaibjbkblbmanamckdldmdcedeeegekeledfefgfkfdgegfggghgkgfhghhhihkhdieifigihikifjgjhjjjkjdkekfkgkhkjkflglhljldmemfmgmhmimjmfngngohdidieifbfagbgahbhchaibiajbjcjknlnmnnnkolomonokpmpkqlqmqnqlrmrnrlsmsnsio\",\"handicap\":0,\"komi\":6.5},\"black\":{\"total\":101,\"stones\":0,\"territory\":94,\"prisoners\":7,\"scoring_positions\":\"aabacadaeaabbbcbdbebacrasarbsbrcscqdrdsdpeqeresepfrfsfogpgqgrgsgnhohphqhrhshnioipiqirisinjojqjrjsjnkokpkqkrkskqlrlslrmsmrnsnrosorpspqqrqsqamanbnaoapbpaqbqarbrcrdrerfrgrhrasbscsdsesfsgshsis\",\"handicap\":0,\"komi\":0}},\"winner\":78080,\"outcome\":\"53.5 points\",\"end_time\":1420524844}", obj);
}
示例4: registerClient
public static void registerClient()
{
_socket = IO.Socket(HostURL);
if (MediateClass.UserVM.UserInfo != null)
{
_socket.Emit("storeMyID", MediateClass.UserVM.UserInfo.UserId);
}
}
示例5: Login
public void Login(string username)
{
if (socket != null)
{
socket.Close();
}
socket = IO.Socket("http://chat.socket.io/");
socket.Connect();
var alert = new AlertDialog.Builder(this).SetMessage("Logging in...").Show();
var chat = new ChatFragment(username, socket, alert);
FragmentManager.BeginTransaction()
.Replace(Resource.Id.frameLayout, chat)
.Commit();
// Tell the server your username (login)
socket.Emit("add user", username);
}
示例6: SocketInit
public static void SocketInit()
{
socket = IO.Socket(Config.apiBase);
socket.Emit("login", Config.UserPhone);
//socket.On("chat", (data) =>
//{
// string str = data.ToString();
// MessageModel messageModel = JsonConvert.DeserializeObject<MessageModel>(str);
// DbService.Current.Add(messageModel);
// UserModel chatUser = new UserModel
// {
// uid = messageModel.myPhone,
// name = messageModel.myName,
// image = messageModel.myImage,
// dream = messageModel.myDream,
// isRead = false
// };
// DbService.Current.InsertOrUpdateFalse(chatUser);
// switch (messageModel.type)
// {
// case 0:
// ToastNotify.Notify("私信 "+messageModel.myName + ":" + messageModel.msg);
// break;
// case 1:
// ToastNotify.Notify("私信 " + messageModel.myName + "向您發送一段了語音");
// break;
// case 2:
// ToastNotify.Notify("私信 " + messageModel.myName + "向您發送了一張圖片");
// break;
// default:
// break;
// }
//});
}
示例7: ListenData
public void ListenData()
{
socket = IO.Socket(Settings.Default.IP_server);
socket.On(Socket.EVENT_CONNECT, () =>
{
Dispatcher.Invoke(() =>
{
// Lview.Items.Add("Connected");
});
});
socket.On(Socket.EVENT_MESSAGE, (data) =>
{
Dispatcher.Invoke(() =>
{
Lview.Items.Add(((Newtonsoft.Json.Linq.JObject)data).ToString());
});
});
socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
{
if (!isError)
{
Dispatcher.Invoke(() =>
{
Lview.Items.Add("XẢY RA LỖI KẾT NỐI VỚI SERVER");
});
isError = true;
}
});
socket.On(Socket.EVENT_ERROR, (data) =>
{
Dispatcher.Invoke(() =>
{
Lview.Items.Add(((Newtonsoft.Json.Linq.JObject)data).ToString());
});
});
#region Socket nhận ChatMessage
socket.On("ChatMessage", (data) =>
{
string Message = ((Newtonsoft.Json.Linq.JObject)data)["message"].ToString();
string Msg = "";
DateTime dt = DateTime.Now;
#region Tin nhắn Welcome!
if (Message == "Welcome!")
{
Dispatcher.Invoke(() =>
{
TextBlock tblock = new TextBlock();
tblock.FontWeight = FontWeights.Bold;
Msg = "Server";
Msg += "\t\t\t\t" + dt.ToLongTimeString();
tblock.Text = Msg;
Lview.Items.Add(tblock);
Lview.Items.Add(Message);
Msg = "------------------------------------------------------";
Lview.Items.Add(Msg);
ClientName = txtName.Text.Trim();
});
if(!ClientName.Equals("Guest"))
{
socket.Emit("MyNameIs", ClientName);
}
socket.Emit("ConnectToOtherPlayer");
}
#endregion
#region Tin nhắn thông báo kết nối và thứ tự 2 người chơi
else if (Message.Contains("<br />"))
{
int index = Message.IndexOf("<br />");
string s1 = Message.Substring(0, index);
string s2 = Message.Substring(index + 6);
Dispatcher.Invoke(() =>
{
TextBlock tblock = new TextBlock();
tblock.FontWeight = FontWeights.Bold;
Msg = "Server";
Msg += "\t\t\t\t" + dt.ToLongTimeString();
tblock.Text = Msg;
Lview.Items.Add(tblock);
Lview.Items.Add(s1);
Lview.Items.Add(s2);
Msg = "------------------------------------------------------";
Lview.Items.Add(Msg);
});
// Nếu kiểu chơi là máy tự chơi online thì thực hiện kiểm tra thứ tự người chơi
// Nếu là người chơi thứ nhất thì cho máy tiến hành tự đánh trước vị trí giữa bàn cờ
if(Type == PlayingType.ComOnline)
{
if (s2 != "You are the second player!")
{
Board.ActivePlayer = CellPlayer.Player2;
Board.PlayAtOnline(Board.BOARD_SIZE / 2 + 1, Board.BOARD_SIZE / 2 + 1);
socket.Emit("MyStepIs", JObject.FromObject(new { row = Board.BOARD_SIZE / 2, col = Board.BOARD_SIZE / 2}));
}
}
//.........這裏部分代碼省略.........
示例8: ShouldWorkWithAcks
public void ShouldWorkWithAcks()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var options = CreateOptions();
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.Emit("ack");
socket.On("ack", (cb) =>
{
var obj = new JObject();
obj["b"] = true;
var iack = (IAck) cb;
iack.Call(5, obj);
});
socket.On("got it",
(data) =>
{
log.Info("got it");
ManualResetEvent.Set();
});
ManualResetEvent.WaitOne();
socket.Close();
}
示例9: ShouldWorkWithAcks2
public void ShouldWorkWithAcks2()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
string message = "";
var options = CreateOptions();
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.Emit("ack2");
var myIListenerImpl = new Acks2ListenerImpl((msg, cb) =>
{
message = (string)msg;
var obj = new JObject();
obj["b"] = true;
var iack = (IAck)cb;
iack.Call(5, obj);
});
socket.On("ack2", myIListenerImpl);
socket.On("got it",
(data) =>
{
log.Info("got it");
ManualResetEvent.Set();
});
ManualResetEvent.WaitOne();
Assert.Equal("hello there", message);
socket.Close();
}
示例10: Cookie
public void Cookie()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var events = new Queue<object>();
var options = CreateOptions();
var uri = CreateUri();
options.Cookies.Add("connect.sid","12345");
socket = IO.Socket(uri, options);
socket.On(Socket.EVENT_CONNECT, () =>
{
log.Info("EVENT_CONNECT");
socket.Emit("get_cookie");
});
socket.On("got_cookie",
(data) =>
{
log.Info("EVENT_MESSAGE data=" + data);
events.Enqueue(data);
ManualResetEvent.Set();
});
ManualResetEvent.WaitOne();
socket.Close();
var cookie = (string)events.Dequeue();
Assert.Equal("connect.sid=12345", cookie);
}
示例11: MessageTestHebrew
public void MessageTestHebrew()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var events = new Queue<object>();
var options = CreateOptions();
options.Transports = ImmutableList.Create<string>(Polling.NAME);
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On(Socket.EVENT_CONNECT, () =>
{
log.Info("EVENT_CONNECT");
socket.Emit("test", "csdataてすとבדיקה");
});
socket.On("hi",
(data) =>
{
log.Info("EVENT_MESSAGE");
events.Enqueue(data);
//socket.Emit("test", "2csdataてすとבדיקה");
ManualResetEvent.Set();
});
//socket.Open();
ManualResetEvent.WaitOne();
socket.Close();
var obj = events.Dequeue();
Assert.Equal("more data", obj);
}
示例12: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
if (socket != null) {
socket.Close ();
}
socket = IO.Socket ("http://chat.socket.io/");
socket.Connect ();
var alert = new UIAlertView ("Log in", "Logging in...", null, null, null);
alert.Show ();
AttachSocketEvents (alert);
// Tell the server your username (login)
socket.Emit ("add user", Username);
entryText.Selected = true;
entryText.Started += (sender, e) => {
if (connected) {
if (!typing) {
typing = true;
socket.Emit ("typing");
}
}
};
entryText.Ended += (sender, e) => {
if (connected) {
if (typing) {
socket.Emit ("stop typing");
typing = false;
}
}
};
sendButton.TouchUpInside += (sender, e) => {
SendMessage ();
socket.Emit ("stop typing");
typing = false;
};
// scroll up when the keyboard appears
NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillShowNotification, notification => {
var info = notification.UserInfo;
var kbFrame = (NSValue)info [UIKeyboard.FrameEndUserInfoKey];
var kbDuration = (NSNumber)info [UIKeyboard.AnimationDurationUserInfoKey];
var animationDuration = kbDuration.DoubleValue;
var keyboardFrame = kbFrame.CGRectValue;
nfloat height = keyboardFrame.Size.Height + 8;
entryTextBottom.Constant = height;
sendButtonBottom.Constant = height;
UIView.Animate (animationDuration, () => View.LayoutIfNeeded ());
});
NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillHideNotification, notification => {
var info = notification.UserInfo;
var kbDuration = (NSNumber)info [UIKeyboard.AnimationDurationUserInfoKey];
var animationDuration = kbDuration.DoubleValue;
entryTextBottom.Constant = 8;
sendButtonBottom.Constant = 8;
UIView.Animate (animationDuration, () => View.LayoutIfNeeded ());
});
}
示例13: Json10000000CharsTest
public void Json10000000CharsTest()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var events = new Queue<object>();
var options = CreateOptions();
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On(Socket.EVENT_CONNECT, () =>
{
log.Info("EVENT_CONNECT");
socket.Emit("json10000000chars");
});
socket.On("json10000000chars",
(data) =>
{
log.Info("EVENT_MESSAGE data=" + data);
events.Enqueue(data);
ManualResetEvent.Set();
});
//socket.Open();
ManualResetEvent.WaitOne();
socket.Close();
var obj = (JObject)events.Dequeue();
var str = (string)obj["data"];
Assert.Equal(10000000, str.Length);
}
示例14: ShouldGetBinaryDataAsAnArraybuffer
public void ShouldGetBinaryDataAsAnArraybuffer()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var events = new Queue<object>();
var options = CreateOptions();
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On("doge", (data) =>
{
events.Enqueue(data);
ManualResetEvent.Set();
});
socket.Emit("doge");
//socket.Open();
ManualResetEvent.WaitOne();
socket.Close();
var binData = (byte[])events.Dequeue();
var exptected = System.Text.Encoding.UTF8.GetBytes("asdfasdf");
var i = 0;
foreach (var b in exptected)
{
Assert.Equal(b, binData[i++]);
}
}
示例15: Worker_DoWork
private void Worker_DoWork(object sender, DoWorkEventArgs e)
{
socket = IO.Socket("ws://gomoku-lajosveres.rhcloud.com:8000");
bool firstConnect = true;
object oldData = new object();
while(true)
{
Thread.Sleep(100);
socket.On("ChatMessage", (data) =>
{
if(firstConnect || oldData != data)
{
firstConnect = false;
string chatSender;
string message = ((JObject)data)["message"].ToString();
if (((JObject)data)["from"] != null)
{
chatSender = ((JObject)data)["from"].ToString();
}
else
{
chatSender = "Server";
}
Application.Current.Dispatcher.Invoke(new Action(() =>
{
ChatMessage chatMessage = new ChatMessage(chatSender, DateTime.Now.ToString("hh:mm:ss tt"), message);
chatBox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
chatBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
chatBox.Items.Add(chatMessage);
if (((JObject)data)["message"].ToString() == "Welcome!")
{
socket.Emit("MyNameIs", txtYourName.Text);
socket.Emit("ConnectToOtherPlayer");
}
}));
oldData = data;
}
});
}
}