2013-01-18 15:55:50 +00:00
|
|
|
using System.Net;
|
|
|
|
using System.Net.Sockets;
|
|
|
|
using System.Text;
|
|
|
|
|
2014-01-08 14:16:39 +00:00
|
|
|
namespace AsterNET.IO
|
2013-01-18 15:55:50 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// ServerSocket using standard socket classes.
|
|
|
|
/// </summary>
|
|
|
|
public class ServerSocket
|
|
|
|
{
|
|
|
|
private TcpListener tcpListener;
|
|
|
|
private Encoding encoding;
|
|
|
|
|
|
|
|
public ServerSocket(int port, IPAddress bindAddress, Encoding encoding)
|
|
|
|
{
|
|
|
|
this.encoding = encoding;
|
|
|
|
tcpListener = new TcpListener(new IPEndPoint(bindAddress, port));
|
|
|
|
tcpListener.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public IO.SocketConnection Accept()
|
|
|
|
{
|
|
|
|
if (tcpListener != null)
|
|
|
|
{
|
|
|
|
TcpClient tcpClient = tcpListener.AcceptTcpClient();
|
|
|
|
if (tcpClient != null)
|
|
|
|
return new IO.SocketConnection(tcpClient, encoding);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
{
|
|
|
|
tcpListener.Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|