All pastes #747550 Raw Edit

Mine

public text v1 · immutable
·published 2007-10-24 03:41 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Server
{
    class TcpServer
    {
        private static AsyncCallback onClientConnectCallback = new AsyncCallback(onClientConnect);

        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.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)
        {

        }
    }
}