public Form1() { InputDialog d = new InputDialog("Connection details", "Which server:port ?", "localhost:9999"); if (d.ShowDialog() != DialogResult.OK) { throw new InvalidOperationException(); } string[] parts = d.Input.Split(':'); string host = parts[0]; string port = parts.Length > 1 ? parts[1] : "9999"; client = new Client(); client.ConnexionRemoved += client_ConnexionRemoved; client.Start(); chats = client.OpenStringChannel(host, port, ChatMessagesChannelId, ChannelDeliveryRequirements.ChatLike); updates = client.OpenSessionChannel(host, port, SessionUpdatesChannelId, ChannelDeliveryRequirements.SessionLike); InitializeComponent(); this.Disposed += Form1_Disposed; }
void Form1_Load(object sender, EventArgs e) { if (Program.kinectEnabled) kinectClient.RecalculateTable(); // Set up GT var config = new DefaultClientConfiguration(); client = new GT.Net.Client(config); client.ErrorEvent += delegate(ErrorSummary es) { Console.WriteLine(es); if (es.Context is GT.Net.CannotConnectException) { Cursor.Show(); MessageBox.Show(this, "Could not connect to server. Make sure the ClientRepeater is started."); quitting = true; } }; client.ConnexionRemoved += client_ConnexionRemoved; client.Start(); updates = client.OpenSessionChannel(host, port, SessionUpdatesChannelId, ChannelDeliveryRequirements.SessionLike); updates.MessagesReceived += updates_SessionMessagesReceived; coords = client.OpenStreamedTuple<int, int>(host, port, PointersChannelId, TimeSpan.FromMilliseconds(25), ChannelDeliveryRequirements.AwarenessLike); coords.StreamedTupleReceived += coords_StreamedTupleReceived; control = client.OpenStringChannel(host, port, ControlChannelId, ChannelDeliveryRequirements.CommandsLike); control.MessagesReceived += control_MessagesReceived; clicks = client.OpenStringChannel(host, port, ClickChannelId, ChannelDeliveryRequirements.CommandsLike); clicks.MessagesReceived += clicks_MessagesReceived; armImages = client.OpenObjectChannel(host, port, ArmImageChannelId, ChannelDeliveryRequirements.AwarenessLike); armImages.MessagesReceived += armImages_MessagesReceived; origins = client.OpenStreamedTuple<int, int>(host, port, OriginsChannelId, TimeSpan.FromMilliseconds(25), ChannelDeliveryRequirements.AwarenessLike); origins.StreamedTupleReceived += origins_StreamedTupleReceived; showArms = client.OpenStreamedTuple<bool>(host, port, ShowArmsChannelId, TimeSpan.FromMilliseconds(25), ChannelDeliveryRequirements.AwarenessLike); showArms.StreamedTupleReceived += showArms_StreamedTupleReceived; kinectCalibrationChannel = client.OpenObjectChannel(host, port, KinectCalibrationChannelId, ChannelDeliveryRequirements.CommandsLike); kinectCalibrationChannel.MessagesReceived += kinectCalibrationChannel_MessagesReceived; boxGrabChannel = client.OpenObjectChannel(host, port, BoxGrabChannelId, ChannelDeliveryRequirements.CommandsLike); boxGrabChannel.MessagesReceived += boxGrabChannel_MessagesReceived; if (Program.useTouch) { tuioClient = new TuioClient(); tuioClient.addTuioListener(this); tuioClient.connect(); } }
private void control_MessagesReceived(IStringChannel channel) { string cmd; while ((cmd = channel.DequeueMessage(0)) != null) { Console.WriteLine("Command received: " + cmd); doCommand(cmd); } }
private void clicks_MessagesReceived(IStringChannel channel) { string click; while ((click = channel.DequeueMessage(0)) != null) { Console.WriteLine("Click received: " + click); string[] parts = click.Split(new char[] {' '}, 3); string button = parts[0]; string type = parts[1]; string player = parts[2]; int clickingPlayerID = int.Parse(player); if (clickingPlayerID == playerID) return; if (type == "down") { if (button == "right") { if (playerID == 0) user2RightDown = true; else if (playerID == 1) user1RightDown = true; } //else //{ // int otherPlayerID = (playerID == 0) ? 1 : 0; // toggleWordBoxUnderCursorNumberDragging(otherPlayerID + 1); //} } else if (type == "up") { if (button == "right") { if (playerID == 0) user2RightDown = false; if (playerID == 1) user1RightDown = false; } //else //{ // if (playerID == 1 && boxBeingDraggedByUser1 != null) // { // boxBeingDraggedByUser1.dropped(); // boxBeingDraggedByUser1 = null; // } // if (playerID == 0 && boxBeingDraggedByUser2 != null) // { // boxBeingDraggedByUser2.dropped(); // boxBeingDraggedByUser2 = null; // } //} } } }
public virtual void Start() { running = true; client.Start(); objectChannel = client.OpenObjectChannel(host, port, 0, ChannelDeliveryRequirements.MostStrict); objectChannel.MessagesReceived += client_ReceivedObjectMessage; stringChannel = client.OpenStringChannel(host, port, 1, ChannelDeliveryRequirements.MostStrict); stringChannel.MessagesReceived += client_ReceivedStringMessage; binaryChannel = client.OpenBinaryChannel(host, port, 2, ChannelDeliveryRequirements.MostStrict); binaryChannel.MessagesReceived += client_ReceivedBinaryMessage; client.StartSeparateListeningThread(); for (int i = 0; i < numberSenders; i++) { Thread t = new Thread(client_StartThread); t.IsBackground = true; t.Name = "Client thread #" + i; t.Start(i); threads.Add(t); } }
private void client_ReceivedStringMessage(IStringChannel channel) { string message; while ((message = channel.DequeueMessage(0)) != null) { if (!StandardObjects.StringMessage.Equals(message)) { Console.WriteLine("Invalid strings message: {0}", message); errorOccurred = true; } if (random.Next(0, 100) < 10) { stringChannel.Send(message); } } }