asternet/Asterisk.2013/Asterisk.NET/IO/ServerSocket.cs

39 lines
811 B
C#
Raw Normal View History

using System.Net;
using System.Net.Sockets;
using System.Text;
2014-01-08 14:16:39 +00:00
namespace AsterNET.IO
{
/// <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();
}
}
}