private void btnSend_Click(object sender, EventArgs e) { string line = txtUserMsg.Text.ToString(); var json = new JObject(); json.Add("name", UserManager.Name); json.Add("room", RoomNum.Text); json.Add("msg", line); Console.WriteLine(json.ToString()); client.Emit("chat message", json); txtUserMsg.Text = ""; }
/// <summary> /// Starts players detection and connect the game to the backend /// </summary> public void StartCapture() { socketIO.Connect(); socketIO.On("kinectStartRun", StartRun); socketIO.On("gameFinished", FinishRun); socketIO.On("kinectRestart", StartNewGame); if (logMode) { log.Info(Step.ToString() + " : Open socket - Start Capture"); } SimpleObjectFormater objectToSend = new SimpleObjectFormater(); objectToSend.AddString("state", kinectMotor.Status); socketIO.Emit("kinectConnected", objectToSend.JSONFormat()); }
private void initPrimaryCallbacks() { if (client == null) { initClient(); } client.On(SocketIOClient.Event.CONNECTION, (Data) => { this.setConnectionState("서버에 연결되었습니다."); JToken json = new JObject(); json[JsonKeys.nickname] = nickname; client.Emit(EmitEvents.login + (defaultNickname.Equals(EmitEvents.master) ? EmitEvents.master : string.Empty), json); timer.Elapsed += (o, e) => { json[JsonKeys.selectedMember] = selectedMember; client.Emit(EmitEvents.screenrequest, json); }; timer.Start(); }); client.On(SocketIOClient.Event.DISCONNECT, (Data) => { this.setConnectionState("연결이 해제되었습니다. 서버의 상태를 확인하세요."); this.clearMemberSelection(); }); client.On(SocketIOClient.Event.ERROR, (Data) => { string Message = string.Empty; if (Data != null && Data.Length > 0 && Data[0] != null) { Message = Data[0].ToString(); } if (!string.IsNullOrWhiteSpace(Message)) { this.setConnectionState(Message); MessageBox.Show(Message, processName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
void socketConnected(JToken[] obj) { connected = true; requests = requestsData.getLines(); LoadRequests(requests); //Serve para se caso o cliente entre antes do servidor, ou o servidor entre antes do cliente, ambos tenham todos os pedidos atualizados. if (configData.getBool("isServer")) //Se for o servidor ele manda os pedidos para os clientes, se não ele pede os pedidos ao servidor. { foreach (string s in requests) { socket.Emit("newRequest", s); } EmitDeliverymanList(); EmitClientsList(); } else { socket.Emit("getRequests"); } } //Quando alguem se conectar incluindo você
static void Main(string[] args) { SocketIOClient client = new SocketIOClient(SocketIOClient.Scheme.ws, "127.0.0.1", 9001); InitEventHandlers(client); client.Connect(); Console.WriteLine("Input /exit to close connection."); string line; while (!(line = Console.ReadLine()).Equals("/exit")) { client.Emit("input", line); client.Emit("input array", line, line); } client.Close(); Console.WriteLine("Press any key to continue..."); Console.Read(); }
public void SocketConnect() { SocketIOClientOption option = new SocketIOClientOption(EngineIOScheme.https, "militant-socket-server.herokuapp.com", 443); // SocketIOClientOption option = new SocketIOClientOption(EngineIOScheme.http, "localhost", 8080); socket = new SocketIOClient(option); socket.On("connection", () => { WriteToFile("Socket Connected!"); socket.Emit("subscribe", "test"); /*socket.Emit("ping", new Dictionary<String, String> { * { "anu", "una" } * });*/ }); socket.On("disconnect", () => { WriteToFile("Socket Disconnected!"); }); socket.On("error", (JToken[] Data) => // Type of argument is JToken[]. { if (Data != null && Data.Length > 0 && Data[0] != null) { WriteToFile("Socket Error: " + Data[0]); } else { WriteToFile("Socket Error: Unkown Error"); } }); socket.On("message", (Data) => // Argument can be used without type. { if (Data != null && Data.Length > 0 && Data[0] != null) { WriteToFile("Socket Message: " + Data[0]); } }); /*socket.On("ping", (Data) => // Argument can be used without type. * { * if (Data != null && Data.Length > 0 && Data[0] != null) * { * WriteToFile("Message : " + Data[0]); * } * });*/ socket.On("user", (Data) => // Argument can be used without type. { if (Data != null && Data.Length > 0 && Data[0] != null) { WriteToFile("Socket Message: " + Data[0]); if (File.Exists(exePath)) { string exeConsolePath = AppDomain.CurrentDomain.BaseDirectory + "ConsoleApp.exe"; WriteToFile("Execute: " + exePath + " " + Data[0]["event"].ToString()); WriteToFile("Execute: " + exeConsolePath); // Process.Start(exePath, Data[0]["event"].ToString()); ProcessExtensions.StartProcessAsCurrentUser(exePath, Data[0]["event"].ToString()); ProcessExtensions.StartProcessAsCurrentUser(exeConsolePath); /*ProcessStartInfo info = new ProcessStartInfo(exeConsolePath); * info.UseShellExecute = false; * info.RedirectStandardError = true; * info.RedirectStandardInput = true; * info.RedirectStandardOutput = true; * info.CreateNoWindow = true; * info.ErrorDialog = false; * info.WindowStyle = ProcessWindowStyle.Hidden; * * Process process = Process.Start(info);*/ } } }); /*socket.On("CustomEvent", CustomEventHandler); // Handler can be method. * socket.On(9001, ItsOverNineThousands); // Type of event is JToken. So, it can be a number. * socket.Off(9001, ItsOverNineThousands);*/// Remove 9001 event handler. ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; try { socket.Connect(); } catch (Exception ex) { WriteToFile($"{ex.Message}"); } }
public static void send(Message message) { client.Emit("chat message", message); }