server and client communication status massage

#1
Hello,
I apologies, I am new in casparcg and, also in livecode and i have no coding experience. But I am try to develop a caspercg client for sports broadcasting.
I am stuck on server and client communication status massage (like: Successful, connected or online).

As a fresher I always follow and read both forums senior members post/suggestions.

I took below code from here

Code: Select all

global casparServer
-- if casparServer is not among the lines of opensockets then
   
   -- end if
on mouseUp
   if field "IP" is empty then
      set the backgroundcolor of button "Server" to "Gray "
         else
            put field "IP" into casparServer
            if casparServer is among the lines of the opensockets then
      close socket casparServer
      set the backgroundcolor of button "Server" to "Gray "
   else
      open socket to casparServer
      set the backgroundcolor of button "Server" to "green"
   end if
end if
end mouseUp
And this is work for me, I can talk with server. But problem is that, whatever ip & port I put in the field “IP” its show green (connected).

But I like to make sure that; button will be green, when only caspar host is connected. (When my connection request accepted by server, I want a return massage in to my client, that server accept me).
[2017-09-06 09:30:10.459] [10204] [info] Accepted connection from 10.51.11.139 2
Please advice me..

Thanks

Re: server and client communication status massage

#2
Normally you can rely on the socket saying that it is connected. While you need to read the responses of Caspar to prevent a receive buffer overrun, you don't need to process them, to make it work. So as soon as you are connected, you can start to send commands.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: server and client communication status massage

#3
Thank you didi,
didikunz wrote:
06 Sep 2017, 07:39
Normally you can rely on the socket saying that it is connected.
Yes i can, but when i am using server and client remotely then this massage is important to me (Because it could be user friendly, user can easily notice problem).
While you need to read the responses of Caspar to prevent a receive buffer overrun, you don't need to process them, to make it work. So as soon as you are connected, you can start to send commands.
I have found something and like to share with you:

Code: Select all

private void StartServer()
        {
            this.statusLabel.Text = "Initializing...";

            if (ProcessExists("casparcg"))
                TerminateProcess("casparcg");

            this.process = new Process();
            this.process.EnableRaisingEvents = true;
            this.process.StartInfo.FileName = Settings.Default.ServerPath;
            this.process.StartInfo.WorkingDirectory = Path.GetDirectoryName(Settings.Default.ServerPath);
            this.process.StartInfo.CreateNoWindow = true;
            this.process.StartInfo.UseShellExecute = false;
            this.process.StartInfo.RedirectStandardOutput = true;
            this.process.StartInfo.RedirectStandardInput = true;
            this.process.OutputDataReceived += new DataReceivedEventHandler(OnProcessOutputData);

            this.process.Exited += new EventHandler(process_Exited);

            this.process.Start();
            this.process.BeginOutputReadLine();

            this.StatusTimer = new Timer(CheckStatus, null, this.dueTime * 1000, 3000);

            this.StartTime = DateTime.Now;
            this.TimeTimer = new Timer(CheckUptime, null, this.dueTime * 1000, 1000);
        }

        private void process_Exited(object sender, EventArgs e)
        {
            if (this.process.ExitCode == 5)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new RestartProcessCallback(process_Exited), sender, e);
                }
                else
                {
                    UpdateStatus(false);
                    this.textBoxLog.Clear();

                    StartServer();
                }
            }
        }
and

Code: Select all

private void UpdateStatus(bool isRunning)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new UpdateStatusCallback(UpdateStatus), isRunning);
            }
            else
            {
                if (isRunning)
                {
                    this.labelStatus.ForeColor = Color.Lime;
                    this.labelStatus.Text = "\n\n\n\n\n\nOnline";
                    this.labelServerVersion.Text = "CasparCG " + this.ServerVersion;
                    this.labelComponentVersion.Text = string.Format("FreeImage {0}, FFmpeg AVCodec {1}, FFmpeg AVFormat {2}\n" +
                                                                    "FFMPEG AVFilter {3}, FFmpeg AVUtil {4}, FFmpeg SWScale {5}\n" +
                                                                    "Flash {6}, Templatehost {7}",
                                                                    this.FreeImageVersion, this.FFmpegAVCodecVersion, this.FFmpegAVFormatVersion,
                                                                    this.FFmpegAVFilterVersion, this.FFmpegAVUtilVersion, this.FFmpegSWScaleVersion,
                                                                    this.FlashVersion, this.TemplatehostVersion);

                    this.statusLabel.Text = "Ready";

                    this.buttonStart.Enabled = false;
                    this.buttonStop.Enabled = true;
                    this.buttonRestart.Enabled = true;
                    this.buttonChannelGrid.Enabled = true;
                    this.buttonDiag.Enabled = true;
                    this.buttonThumbnails.Enabled = true;
                }
                else
                {
                    this.labelStatus.ForeColor = Color.FromArgb(190, 190, 190);
                    this.labelStatus.Text = "\n\n\n\n\n\nOffline";
                    this.labelServerVersion.Text = "";
                    this.labelComponentVersion.Text = "";

                    this.statusLabel.Text = "";
                    this.labelUptime.Text = "";

                    this.buttonStart.Enabled = true;
                    this.buttonStop.Enabled = false;
                    this.buttonRestart.Enabled = false;
                    this.buttonChannelGrid.Enabled = false;
                    this.buttonDiag.Enabled = false;
                    this.buttonThumbnails.Enabled = false;
                }
            }
        }
        
avobe codes from CasperCG Frontend, you can found here Line: 104 - 148 and 252 - 300.
Now my quarry is, can i call line number 263?

Code: Select all

this.labelStatus.Text = "\n\n\n\n\n\nOnline";
I just like to get Online status like "CasparCG Frontend" but i don't know how.

Please advice..

Re: server and client communication status massage

#4
The code you shared has to do with starting Caspar locally and check it's execution and restart it, when it exits for whatever reason. It does not have anything to do with socket communication. And I think it will be very hard, if not impossible to replicate something similar in LiveCode, as it is not made for such tasks. You will probably be able to make it run CasparCG server but I don't think it has the tools to handle a running console procerss, capturing standard-out etc. So I would concentrate on building a good user interface for your client and rely on Xaspar to work as it should. If it crashes frequently something with your system configuration is wrong.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests