本文整理匯總了C#中Quobject.SocketIoClientDotNet.Client.Socket.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# Socket.Close方法的具體用法?C# Socket.Close怎麽用?C# Socket.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Quobject.SocketIoClientDotNet.Client.Socket
的用法示例。
在下文中一共展示了Socket.Close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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);
}
示例2: MessageTest
public void MessageTest()
{
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("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.Equal("more data", obj);
}
示例3: Connect
public void Connect()
{
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.On(Socket.EVENT_CONNECT, () =>
{
log.Info("EVENT_CONNECT");
socket.Disconnect();
});
socket.On(Socket.EVENT_DISCONNECT,
(data) =>
{
log.Info("EVENT_DISCONNECT");
Message = (string) data;
ManualResetEvent.Set();
});
//socket.Open();
ManualResetEvent.WaitOne();
socket.Close();
Assert.AreEqual("io client disconnect", this.Message);
}
示例4: ShouldReceiveUtf8MultibyteCharacters
public void ShouldReceiveUtf8MultibyteCharacters()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
var events = new Queue<object>();
var correct = new string[]
{
"てすと",
"Я Б Г Д Ж Й",
"Ä ä Ü ü ß",
"李O四",
"utf8 — string"
};
var i = 0;
var options = CreateOptions();
options.Transports = ImmutableList.Create<string>(Polling.NAME);
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On("takeUtf8", (data) =>
{
events.Enqueue(data);
i++;
log.Info(string.Format("takeUtf8 data={0} i={1}",(string)data,i));
if (i >= correct.Length)
{
ManualResetEvent.Set();
}
});
socket.Emit("getUtf8");
ManualResetEvent.WaitOne();
socket.Close();
var j = 0;
foreach (var obj in events)
{
var str = (string) obj;
Assert.Equal(correct[j++], str);
}
}
示例5: ShouldWorkWithFalse
public void ShouldWorkWithFalse()
{
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, () =>
{
socket.Emit("false");
});
socket.On("false",
(data) =>
{
events.Enqueue(data);
ManualResetEvent.Set();
});
ManualResetEvent.WaitOne();
socket.Close();
var obj = events.Dequeue();
Assert.False((bool) obj);
}
示例6: ShouldReceiveDateWithAckAsAction
public void ShouldReceiveDateWithAckAsAction()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
Message = "";
Number = 0;
ManualResetEvent = new ManualResetEvent(false);
var obj = new JObject();
obj["b"] = true;
var options = CreateOptions();
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.Emit("getAckDate", (date, n) =>
{
log.Info("getAckDate data=" + date);
Message = ((DateTime)date).ToString("O");
Number = int.Parse(n.ToString());
ManualResetEvent.Set();
}, obj);
ManualResetEvent.WaitOne();
Assert.Equal(28, Message.Length);
Assert.Equal(5, Number);
socket.Close();
}
示例7: 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++]);
}
}
示例8: ShouldNotTryToReconnectAndShouldFormAConnectionWhenConnectingToCorrectPortWithDefaultTimeout
public void ShouldNotTryToReconnectAndShouldFormAConnectionWhenConnectingToCorrectPortWithDefaultTimeout()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
Flag = false;
var options = CreateOptions();
options.Reconnection = true;
options.ReconnectionDelay = 10;
var uri = CreateUri();
var manager = new Manager(new Uri(uri), options);
socket = manager.Socket("/valid");
manager.On(Manager.EVENT_RECONNECT_ATTEMPT, () =>
{
Flag = true;
});
socket.On(Socket.EVENT_CONNECT, async() =>
{
// set a timeout to let reconnection possibly fire
log.Info("EVENT_CONNECT");
await Task.Delay(1000);
ManualResetEvent.Set();
});
ManualResetEvent.WaitOne();
log.Info("after WaitOne");
socket.Close();
manager.Close();
Assert.False(Flag);
}
示例9: 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);
}
示例10: 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);
}
示例11: ShouldSendBinaryDataAsAnArraybufferMixedWithJson
public void ShouldSendBinaryDataAsAnArraybufferMixedWithJson()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
Flag = false;
var buf = System.Text.Encoding.UTF8.GetBytes("howdy");
var jobj = new JObject();
jobj.Add("hello", "lol");
jobj.Add("message", buf);
jobj.Add("goodbye", "gotcha");
var options = CreateOptions();
//options.Transports = ImmutableList.Create<string>(Polling.NAME);
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On("jsonbuff-ack", () =>
{
Flag = true;
ManualResetEvent.Set();
});
socket.On(Socket.EVENT_DISCONNECT, () =>
{
log.Info("EVENT_DISCONNECT");
});
socket.Emit("jsonbuff", jobj);
ManualResetEvent.WaitOne();
Task.Delay(1).Wait();
log.Info("About to wait 1sec");
//Task.Delay(1000).Wait();
log.Info("About to call close");
socket.Close();
//Task.Delay(1000).Wait();
Assert.True(Flag);
log.Info("Finish");
}
示例12: BuffAck
public void BuffAck()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
Flag = false;
var exptected = System.Text.Encoding.UTF8.GetBytes("asdfasdf");
var options = CreateOptions();
//options.Transports = ImmutableList.Create<string>(Polling.NAME);
var uri = CreateUri();
socket = IO.Socket(uri, options);
socket.On("buffack", () =>
{
Flag = true;
ManualResetEvent.Set();
});
socket.Emit("buffa", exptected);
ManualResetEvent.WaitOne();
//Task.Delay(8000).Wait();
socket.Close();
//Task.Delay(4000).Wait();
Assert.True(Flag);
log.Info("Finish");
}
示例13: ListenData
//.........這裏部分代碼省略.........
{
rtb_conversation.AppendText(string.Format("Server - {0}", DateTime.Now.ToString("HH:mm:ss tt")) + Environment.NewLine);
rtb_conversation.AppendText(str1 + Environment.NewLine);
rtb_conversation.AppendText(str2 + Environment.NewLine);
rtb_conversation.AppendText("--------------------------------------------------------" + Environment.NewLine);
rtb_conversation.ScrollToEnd();
});
//If BOT online and have first turn, lets it plays at [5,5]
if (ChosingMode.mode == 4)
{
socket.Emit("ChatMessage", botChat[0]);
if (str2 != "You are the second player!")
{
choosedRow = 5;
choosedCol = 5;
socket.Emit("MyStepIs", JObject.FromObject(new { row = 5, col = 5 }));
}
}
}
//Message from other player
else if (((Newtonsoft.Json.Linq.JObject)data).Count > 1)
{
Dispatcher.Invoke(() =>
{
rtb_conversation.AppendText(string.Format("{0} - {1}", ((Newtonsoft.Json.Linq.JObject)data)["from"].ToString(), DateTime.Now.ToString("HH:mm:ss tt")) + Environment.NewLine);
rtb_conversation.AppendText(string.Format("{0}", message) + Environment.NewLine);
rtb_conversation.AppendText("--------------------------------------------------------" + Environment.NewLine);
rtb_conversation.ScrollToEnd();
});
}
//Message from server
else
{
Dispatcher.Invoke(() =>
{
rtb_conversation.AppendText(string.Format("Server - {0}", DateTime.Now.ToString("HH:mm:ss tt")) + Environment.NewLine);
rtb_conversation.AppendText(string.Format("{0}", message) + Environment.NewLine);
rtb_conversation.AppendText("--------------------------------------------------------" + Environment.NewLine);
rtb_conversation.ScrollToEnd();
});
}
});
//End of round
socket.On("EndGame", (data) =>
{
Dispatcher.Invoke(() =>
{
string message = ((Newtonsoft.Json.Linq.JObject)data)["message"].ToString();
rtb_conversation.AppendText(string.Format("Server - {0}", DateTime.Now.ToString("HH:mm:ss tt")) + Environment.NewLine);
rtb_conversation.AppendText(string.Format("{0}", message) + Environment.NewLine);
rtb_conversation.AppendText("--------------------------------------------------------" + Environment.NewLine);
rtb_conversation.ScrollToEnd();
MessageBox.Show(message);
thread.Interrupt();
socket.Close();
this.Close();
});
});
//Recieve game info
socket.On("NextStepIs", (data) =>
{
int player = int.Parse(((Newtonsoft.Json.Linq.JObject)data)["player"].ToString()) + 1;
int row = int.Parse(((Newtonsoft.Json.Linq.JObject)data)["row"].ToString());
int col = int.Parse(((Newtonsoft.Json.Linq.JObject)data)["col"].ToString());
//player = 1: client turn
if (player == 1)
{
Dispatcher.Invoke(() =>
{
btnList[row][col].Content = AddChess(row, col, player);
gp.board[row, col] = player;
});
}
//player = 2 other turn
else
{
Dispatcher.Invoke(() =>
{
btnList[row][col].Content = AddChess(row, col, player);
gp.board[row, col] = player;
});
if (ChosingMode.mode == 4)
{
Thread aiThread = new Thread(new ThreadStart(gp.ChooseChess));
aiThread.Start();
Thread.Sleep(10);
choosedCol = gp.col;
choosedRow = gp.row;
gp.board[choosedRow, choosedCol] = 2;
socket.Emit("MyStepIs", JObject.FromObject(new { row = choosedRow, col = choosedCol }));
socket.Emit("ChatMessage", botChat[rd.Next(1, botChat.Count())] );
}
}
});
}
示例14: ShouldEmitDateAsDate
public void ShouldEmitDateAsDate()
{
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("takeDate", (data) =>
{
log.Info("takeDate");
events.Enqueue(data);
ManualResetEvent.Set();
});
socket.Emit("getDate");
//socket.Open();
ManualResetEvent.WaitOne();
socket.Close();
var obj = events.Dequeue();
Assert.IsInstanceOfType(obj, typeof(DateTime) );
}
示例15: ShouldFireErrorOnSocket
public void ShouldFireErrorOnSocket()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("Start");
ManualResetEvent = new ManualResetEvent(false);
Flag = false;
var events = new Queue<object>();
var options = CreateOptions();
options.Reconnection = true;
var uri = CreateUri();
var manager = new Manager(new Uri(uri), options);
socket = manager.Socket("/timeout_socket");
socket.On(Socket.EVENT_ERROR, (e) =>
{
var exception = (EngineIOException) e;
log.Info("EVENT_ERROR");
events.Enqueue(exception.code);
socket.Close();
manager.Close();
ManualResetEvent.Set();
});
socket.On(Socket.EVENT_CONNECT, () =>
{
log.Info("EVENT_CONNECT");
manager.EngineSocket.OnPacket(new Packet(Packet.ERROR, "test"));
});
ManualResetEvent.WaitOne();
var obj = (string)events.Dequeue();
Assert.Equal("test", obj);
}