При создании экземпляра класса InputUserInfoForm
сервер принимает соединение, хотя в данном классе нет ничего для соединения с ним. Уже час ищу ошибку, не могу понять в чём проблема.
Вот код класса InputUserInfoForm
:
using System;
using System.Windows.Forms;
namespace TextEditorClient
{
public partial class InputUserInfoForm : Form
{
private string fileName = "";
private int fileNameLength = 0;
public InputUserInfoForm(int fnl)
{
fileNameLength = fnl;
InitializeComponent();
comboBox1.Items.Add("Писатель");
comboBox1.Items.Add("Обозреватель");
}
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
fileName = textBox1.Text;
this.Close();
}
public int CheckFileName()
{
fileName = textBox1.Text;
if (fileName == "")
{
MessageBox.Show("Имя файла не может быть пустым.", "Ошибка!");
return 1;
}
if (fileName.Length >= fileNameLength)
{
MessageBox.Show("Максимальная длина имени файла 50 символов.", "Ошибка!");
return 1;
}
return 0;
}
}
}
Код сервера:
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace TextEditorServer
{
class Program
{
static int port = 8888;
static TcpListener server;
private static void Main()
{
try
{
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
server = new TcpListener(localAddr, port);
server.Start();
while (true)
{
Console.WriteLine("Waiting for a connection... ");
TcpClient clientConnection = server.AcceptTcpClient();
Console.WriteLine("Connected!");
ClientClass newClient = new ClientClass(clientConnection);
Thread newClientThread = new Thread(new ThreadStart(newClient.Process));
newClientThread.Start();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (server != null)
server.Stop();
}
}
}
}