using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace tMaxima
{
public partial class VaporMaxima : Form
{
Process Maxima;
public VaporMaxima()
{
InitializeComponent();
Send.Enabled = false;
SendText.Enabled = false;
ControlBox = false;
Exit.Enabled = false;
KeyPreview = true;
}
#region Form Component
private void VaporMaxima_Load(object sender, EventArgs e)
{
w1.LocalPort = 1358; //the port I picked to use for the connection
w1.Listen(); //this command opens the port and waits for a connection
Maxima = new Process();
Maxima.StartInfo.FileName = "c:/Maxima-5.17.1/bin/maxima.bat";
Maxima.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Maxima.StartInfo.Arguments = "-s 1358";
Maxima.Start();
}
private void ExitMenu_Click(object sender, EventArgs e)
{
this.Close();
}
private void Send_Click(object sender, EventArgs e)
{
try
{
if (SendText.Text != "")
{
w1.SendData((object)SendText.Text); // now we send the data that we wrote in sendText textbox
DataInput.Text += SendText.Text; // we write to the screen what we said to the client
SendText.Text = ""; // we clear the command line
}
}
catch (Exception ex)
{
DataInput.Text += "\n - Error : " + ex.Message;
}
}
private void Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form_Closing(object sender, FormClosingEventArgs e)
{
try
{
SendText.Text = "quit();";
Send_Click(sender, e);
w1.Close();
System.Threading.Thread.Sleep(2000);
MessageBox.Show("Maxima Session Closed" + Maxima.ExitCode.ToString().Substring(1, 0), "Maxima has been Closed", System.Windows.Forms.MessageBoxButtons.OK);
}
catch (Exception ex)
{
if (MessageBox.Show("Error Closing Maxima. The Maxima Process May Still be Running: " + ex.Message, "Error Closing Maxima", System.Windows.Forms.MessageBoxButtons.RetryCancel) == DialogResult.Retry)
MessageBox.Show("Maxima Session Closed " + Maxima.ExitCode.ToString().Substring(1, 0), "Maxima is Closed");
else
{
DataInput.Text += "\nConnected ";
}
}
}
#endregion s
#region Handle Socket Events
// this executes when disconnecting from the client
void w1_CloseEvent(object sender, System.EventArgs e)
{
Send.Enabled = false;
SendText.Enabled = false;
ControlBox = false;
Exit.Enabled = false;
w1.Close(); //now we close winsock
}
// this event is called when a client requests a connection with the server
private void w1_ConnectionRequest(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent e)
{
w1.Close ();
w1.Accept (e.requestID); // accept the connection request to the server...
DataInput.Text += "\nConnected ";
}
// this event is called when an error fires
void w1_Error(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent e)
{
DataInput.Text += "\n - Error\n" + e.description ; // now we write in the screen the error
}
// this event is called when the client sent data to the server
void w1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
{
Send.Enabled = true;
SendText.Enabled = true;
ControlBox = true;
Exit.Enabled = true;
Refresh();
String data = ""; // data is the variable that stores the incoming data
Object dat = (object)data; // dat is type object
// the methode getData of winsock take only work with type object
// and we input data in the variable to use it next time by ref
w1.GetData(ref dat);// with this command the data is being stored in the dat variable so
// we can use it
data = (String)dat; // change back the object dat to string
DataInput.Text += "\n" + data; // write data to the screen
DataInput.SelectionStart = DataInput.TextLength;
DataInput.ScrollToCaret();
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
DataInput.Paste();
}
}
}