public static void sendMessage(RemoteMessage message, String host, int port) { TcpClient myclient = new TcpClient(host, port); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(myclient.GetStream(), message); myclient.Close(); }
protected void takeDelayedPhoto(object s, EventArgs e) { try { int delay = Convert.ToInt32(((ImageButton)s).CommandArgument); RemoteMessage message = new RemoteMessage(delay, RemoteCommand.TakePhoto); RemoteClient.sendMessage(message, host, port); } catch (Exception ex) { Response.Write("<script language=\"javascript\" type=\"text/javascript\">alert('Unable to take photo because " + ex.Message + "');</script>"); } }
private void interpretMessage(RemoteMessage message) { switch (message.RemoteCommand) { case RemoteCommand.TakePhoto: Console.WriteLine("Waiting for "+message.Delay+"ms"); TakePhoto(message.Delay); break; case RemoteCommand.DepressButton: DepressButton(); break; default: throw new NotImplementedException("No code has been written to handle the [" + message + "] command!"); } }