old_flsystem/FLSystem/Forms/TCPForm.cs

67 lines
2.3 KiB
C#
Raw Normal View History

2022-09-20 03:10:29 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UI.Framework.Forms;
using Api.Framework;
namespace FLSystem.Forms
{
/// <summary>
/// Socket服务器设置窗体
/// </summary>
public partial class TCPForm : BaseForm
{
public TCPForm()
{
InitializeComponent();
this.numericUpDown1.Value = ApiClient.Setting.ServerConfig.SocketPort;
var socketPassword = ApiClient.Setting.ServerConfig.SocketPassword;
if (socketPassword.Length > 16)
socketPassword = socketPassword.Substring(0, 16);
this.textBox1.Text = socketPassword;
if (ApiClient.Server != null && ApiClient.Server.State == SuperSocket.SocketBase.ServerState.Running)
{
numericUpDown1.Enabled = linkLabel2.Enabled = false;
this.simpleButton1.Text = "关闭Socket服务器";
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
try
{
if (this.simpleButton1.Text == "关闭Socket服务器")
{
numericUpDown1.Enabled = linkLabel2.Enabled = true;
ApiClient.StopSocketServer();
this.simpleButton1.Text = "启动Socket服务器";
}
else
{
if (string.IsNullOrEmpty(this.textBox1.Text)) linkLabel2_LinkClicked(null, null);
if (ApiClient.StartSocketServer((int)this.numericUpDown1.Value, this.textBox1.Text))
{
numericUpDown1.Enabled = linkLabel2.Enabled = false;
this.simpleButton1.Text = "关闭Socket服务器";
}
}
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
}
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.textBox1.Text = CsharpHttpHelper.HttpExtend.GetMD5String(Guid.NewGuid().ToString()).ToLower().Substring(0, 16);
}
}
}