току для отримання даних.");
connection.Thread = new Thread (ProcessConnection);. Thread.IsBackground = true;. Thread.Start (connection);
// Зберігаємо сокет (_connections) _connections.Add (connection);
}
} void ProcessConnection (object state)
{connection = (ConnectionInfo) state; [] buffer = new byte [1000]; message;. WriteLine ("Очікування даних ...");
{(true)
{= new byte [1000]; bytesRead = connection.Socket.Receive (buffer); (bytesRead> 0)
{= Encoding.Unicode.GetString (buffer, 0, bytesRead);. WriteLine ("Отримано дані: r n" + message); (ConnectionInfo conn in _connections). Socket. Send (buffer, bytesRead, SocketFlags.None); = String.Empty;
}
}
} (SocketException exc)
{(exc.SocketErrorCode.ToString () == "ConnectionReset")
{. WriteLine ("Користувач відключився поточне кол-во користувачів:" + _connections.Count.ToString ());
}
{. WriteLine ("Socket exception:" + exc.SocketErrorCode);
}
} (Exception exc)
{. WriteLine ("Exception:" + exc);
}
{. Socket.Close (); (_connections) _connections.Remove ();
}
}
}
}
Лістинг модуля клієнта
using System;
using
{partial class Form1: Form
{hostName;// DNS-ім'я сервераport = 10000;// Номер портаstream; tcpClient; class Class1
{
[DllImport ("netapi32.dll", EntryPoint = "NetServerEnum")] static extern NERR NetServerEnum ([MarshalAs (UnmanagedType.LPWStr)] string ServerName, int Level, out IntPtr BufPtr, int PrefMaxLen, ref int EntriesRead, ref int TotalEntries, SV_101_TYPES ServerType, [MarshalAs (UnmanagedType.LPWStr)] string Domain, int ResumeHandle);
[DllImport ("netapi32.dll", EntryPoint = "NetApiBufferFree")] static extern NERR NetApiBufferFree (IntPtr Buffer);
[Flags] enum SV_101_TYPES: uint
{_TYPE_WORKSTATION = 0x00000001, _TYPE_SERVER = 0x00000002, _TYPE_SQLSERVER = 0x00000004, _TYPE_DOMAIN_CTRL = 0x00000008, _TYPE_DOMAIN_BAKCTRL = 0x00000010, _TYPE_TIME_SOURCE = 0x00000020, _TYPE_AFP = 0x00000040, _TYPE_NOVELL = 0x00000080, _TYPE_DOMAIN_MEMBER = 0x00000100, _TYPE_PRINTQ_SERVER = 0x00000200, _TYPE_DIALIN_SERVER = 0x00000400, _TYPE_XENIX_SERVER = 0x00000800, _TYPE_SERVER_UNIX = SV_TYPE_XENIX_SERVER, _TYPE_NT = 0x00001000, _TYPE_WFW = 0x00002000, _TYPE_SERVER_MFPN = 0x00004000,...