rendered paste bodyusing System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Server
{
class TcpServer
{
private readonly AsyncCallback onClientConnectCallback;
private Socket mSock;
private IPEndPoint ipInfo;
private bool isListening;
public Socket MainSocket { get { return this.mSock; } }
public IPEndPoint IPInfo { get { return this.ipInfo; } }
public bool IsListening { get { return this.isListening; } }
public TcpServer(IPAddress ip, int port)
{
this.onClientConnectCallback = new AsyncCallback(this.onClientConnect);
this.mSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
this.ipInfo = new IPEndPoint(ip, port);
this.isListening = false;
}
public void Start()
{
this.Start(-1);
}
public void Start(int backlog)
{
this.mSock.Bind(this.ipInfo);
this.mSock.Listen(backlog);
this.isListening = true;
}
public void Stop()
{
this.mSock.Shutdown(SocketShutdown.Both);
this.mSock.Close(5);
this.isListening = false;
}
private void onClientConnect(IAsyncResult asyn)
{
}
}
}