proxy-server-sharp/ProxyServerSharp/MainForm.cs

80 lines
2.4 KiB
C#
Raw Normal View History

2015-06-29 20:34:25 -05:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ProxyServerSharp.Implementation;
using ProxyServerSharp.Interfaces;
2015-06-29 20:34:25 -05:00
namespace ProxyServerSharp
{
public partial class MainForm : Form
{
IProxyCore _proxyCore;
2015-06-29 20:34:25 -05:00
public MainForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 8; i < 16; i++)
transferUnitSizeComboBox.Items.Add(Math.Pow(2, i).ToString());
transferUnitSizeComboBox.SelectedIndex = 4;
}
void server_RemoteConnect(object sender, System.Net.IPEndPoint iep)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(delegate()
{
debugTextBox.AppendText("Connecting to " + iep.ToString() + "\r\n");
}));
}
}
void server_LocalConnect(object sender, System.Net.IPEndPoint iep)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(delegate()
{
debugTextBox.AppendText("Connection from " + iep.ToString() + "\r\n");
}));
}
}
private void startProxyButton_Click(object sender, EventArgs e)
{
if (startProxyButton.Text == "Start")
{
var config = new ProxyServerConfiguration()
{
Port = int.Parse(portTextBox.Text),
TransferUnitSize = int.Parse((string)transferUnitSizeComboBox.SelectedItem)
};
_proxyCore = ProxyCoreFactory.Create(config, Enums.ProxyType.Socks4);
_proxyCore.LocalConnect += new LocalConnectEventHandler(server_LocalConnect);
_proxyCore.RemoteConnect += new RemoteConnectEventHandler(server_RemoteConnect);
_proxyCore.Start();
2015-06-29 20:34:25 -05:00
statusLabel.Text = "Started";
startProxyButton.Text = "Stop";
}
else
{
_proxyCore.Shutdown();
statusLabel.Text = "Stopped";
startProxyButton.Text = "Start";
2015-06-29 20:34:25 -05:00
}
}
}
}