本文整理匯總了C#中Quobject.SocketIoClientDotNet.Client.Socket類的典型用法代碼示例。如果您正苦於以下問題:C# Socket類的具體用法?C# Socket怎麽用?C# Socket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Socket類屬於Quobject.SocketIoClientDotNet.Client命名空間,在下文中一共展示了Socket類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: initSocket
private void initSocket(string server)
{
socket = IO.Socket(server);
socket.On(Socket.EVENT_CONNECT, async () =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
viewModel.ServerStatus = "Connected";
}).AsTask();
});
socket.On(Socket.EVENT_CONNECT_ERROR, async () =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
viewModel.ServerStatus = "Can't connect";
}).AsTask();
});
socket.On(Socket.EVENT_DISCONNECT, async () =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
viewModel.ServerStatus = "Not connected";
}).AsTask();
});
}
示例2: WebNfcListener
public WebNfcListener(string ident)
{
if (!ident.Contains("@"))
throw new ArgumentException("Invalid ident - missing @");
var parts = ident.Split('@');
if(parts.Length != 2)
throw new ArgumentException("Invalid ident - invalid length");
_endpoint = parts[0];
_address = parts[1];
_ioHandler = IO.Socket(_address);
_ioHandler.On(Socket.EVENT_CONNECT, (obj) =>
{
OnConnected?.Invoke();
});
_ioHandler.On("scanner.registered", (obj) =>
{
var scanner = NfcScanner.FromJson(obj as string);
OnRegistered?.Invoke(scanner);
});
_ioHandler.On("scanner.scanned", (obj) =>
{
var scanner = NfcScanner.FromJson(obj as string);
});
}
示例3: Initialize
/// <summary>
/// Initializes the socket and sets-up all the events to listen to.
/// Server certifaction validation is ingnored, because the server uses a self-signed certificate.
/// </summary>
/// <param name="adress"></param>
public void Initialize(string adress, bool ignoreServerCertificateValidation) {
_socket = IO.Socket(adress, new IO.Options() { Secure = true, IgnoreServerCertificateValidation = ignoreServerCertificateValidation });
_socket.On("register-accepted", (data) => {
Console.WriteLine("Succesfull connected with Server");
});
_socket.On("register-failed", (data) => {
string errorMessage = data.ToString();
Console.WriteLine("Failed to connected with Server: {0}", errorMessage);
});
_socket.On("message", (data) => {
var message = JsonConvert.DeserializeObject<JsonReceivedMessage>(data.ToString());
OnMessageReceived(this, new MessageReceivedEventArgs() { Identifier = message.Sender, Message = message.Message, TimeStamp = message.Timestamp, GroupHash = message.GroupHash });
});
_socket.On("user-search", (data) => {
List<Client> clients = JsonConvert.DeserializeObject<List<Client>>(data.ToString());
OnUserSearch(this, new UserSearchEventArgs() { FoundMembers = clients });
});
_socket.On("user-confirm", (data) => {
var client = JsonConvert.DeserializeObject<Client>(data.ToString());
OnUserConfirm(this, new UserConfirmEventArgs() { PublicKey = client.PublicKey, UserName = client.UserName });
});
_socket.On("joined-group", (data) => {
var message = JsonConvert.DeserializeObject<JsonJoinedGroup>(data.ToString());
OnGroupJoined(this, new GroupJoinedEventArgs() { GroupName = message.GroupName, GroupHash = message.GroupHash, Members = message.Members });
});
_socket.Connect();
}
示例4: 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);
}
示例5: AttachToSocket
public void AttachToSocket(Socket socket)
{
socket.On("Play", Play);
socket.On("Pause", Pause);
socket.On("Stop", Stop);
socket.On("SetTrackId", (id) => SetTrackId((string) id));
}
示例6: 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.Equal("io client disconnect", this.Message);
}
示例7: 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);
}
示例8: ChatFragment
public ChatFragment(string username, Socket socket, AlertDialog alert)
{
this.username = username;
this.socket = socket;
this.adapter = new ChatAdapter(chatItems);
AttachSocketEvents(alert);
}
示例9: registerClient
public static void registerClient()
{
_socket = IO.Socket(HostURL);
if (MediateClass.UserVM.UserInfo != null)
{
_socket.Emit("storeMyID", MediateClass.UserVM.UserInfo.UserId);
}
}
示例10: SwitchClient
public SwitchClient(Uri serverUrl)
{
this.serverUrl = serverUrl;
socket = IO.Socket(serverUrl);
socket.On(Socket.EVENT_CONNECT, OnConnect);
socket.On(SwitchEvent, OnSwitchEvent);
}
示例11: 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());
});
}
}
示例12: GameInit
private void GameInit()
{
PlayPanel.Children.Clear();
CreatePlayGround();
ChatTb.Focus();
MyName = NameTb.Text;
if (Board.CurrentMode == PlayMode.Online || Board.CurrentMode == PlayMode.MachineVsOnline)
{
GomokuSocket = IO.Socket(WebConfigurationManager.AppSettings.Get("ServerAddress"));
InitConnect(); //Initialize Connect
ChatConnect(); //Create Thread for chatting
GamePlayConnect(); //Create Threads for playing
}
}
示例13: connect
public LinkIO connect(Action listener)
{
IO.Options opts = new IO.Options();
Dictionary<String, String> query = new Dictionary<String, String>();
query.Add("user", user);
if(id != "")
query.Add("id", id);
opts.Query = query;
opts.AutoConnect = false;
socket = IO.Socket("http://" + serverIP, opts);
socket.On("users", (e) =>
{
if (userInRoomChangedListener != null)
userInRoomChangedListener.Invoke(((JArray) e).ToObject<List<User>>());
});
socket.On(Socket.EVENT_CONNECT, () =>
{
connected = true;
listener.Invoke();
});
socket.On(Socket.EVENT_DISCONNECT, () =>
{
connected = false;
});
socket.On("event", (Object o) =>
{
JObject evt = (JObject) o;
String eventName = (String) evt.SelectToken("type");
if (eventListeners.ContainsKey(eventName))
{
eventListeners[eventName].Invoke(new Event(evt));
}
});
socket.Connect();
return this;
}
示例14: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
bSend.TouchUpInside += (object sender, EventArgs e) => {
var message = tfMessage.Text;
socket.Emit("message", message);
};
socket = IO.Socket(Constants.HOST);
socket.On ("message", (message) => {
InvokeOnMainThread(() => {
var alert = new UIAlertView("From server:", message.ToString(), null, "OK", null);
alert.Show();
});
});
}
示例15: 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);
}