Пример #1
0
        public BaseSocket(Protocols Type)
        {
            this.Type = Type;

            events       = new EventBaseList();
            sendCommands = new SendCommandList();

            SendBufferSize    = Constants.SEND_BUFFER_SIZE;
            ReceiveBufferSize = Constants.RECEIVE_BUFFER_SIZE;

            Socket = SocketUtilities.CreateSocket(Type);
            SocketUtilities.SetBlocking(Socket, false);
            SocketUtilities.SetReceiveTimeout(Socket, Constants.RECEIVE_TIMEOUT);
            SocketUtilities.SetSendTimeout(Socket, Constants.SEND_TIMEOUT);
            SocketUtilities.SetTimeToLive(Socket, Constants.TIME_TO_LIVE);
            SocketUtilities.SetIPv6OnlyEnabled(Socket, false);
            //SocketUtilities.SetChecksumEnabled(Socket, false);

            if (Type == Protocols.TCP)
            {
                SocketUtilities.SetNagleAlgorithmEnabled(Socket, false);
            }

            Statistics = new NetworkingStatistics();

            MultithreadedCallbacks = true;
            MultithreadedReceive   = true;
            MultithreadedSend      = true;
        }
Пример #2
0
        protected override bool HandleSendCommand(SendCommand Command)
        {
            if (!SocketUtilities.GetIsReady(Socket))
            {
                return(false);
            }

            SendOverSocket(Socket, Command.Buffer);

            return(true);
        }
Пример #3
0
        public void Bind(IPEndPoint EndPoint)
        {
            if (EndPoint.AddressFamily == AddressFamily.InterNetwork)
            {
                EndPoint.Address = SocketUtilities.MapIPv4ToIPv6(EndPoint.Address);
            }

            LocalEndPoint = EndPoint;

            Socket.Bind(EndPoint);
        }
Пример #4
0
        public void Connect(IPEndPoint EndPoint)
        {
            if (EndPoint.AddressFamily == AddressFamily.InterNetwork)
            {
                EndPoint.Address = SocketUtilities.MapIPv4ToIPv6(EndPoint.Address);
            }

            RemoteEndPoint = EndPoint;

            ConnectInternal(EndPoint);
        }
        public override void UnBind()
        {
            for (int i = 0; i < clients.Count; ++i)
            {
                SocketUtilities.CloseSocket(clients[i].Socket);
            }

            clients.Clear();

            base.UnBind();
        }
Пример #6
0
        protected void RunReceiveThread()
        {
            SocketUtilities.SetSendBufferSize(Socket, SendBufferSize);
            SocketUtilities.SetReceiveBufferSize(Socket, ReceiveBufferSize);
            ReceiveBuffer = new byte[ReceiveBufferSize];

            if (!MultithreadedReceive)
            {
                return;
            }

            receiveThread = new Thread(ReceiverWorker);
            receiveThread.Start();
        }
Пример #7
0
        protected void Shutdown()
        {
            if (MultithreadedReceive)
            {
                receiveThread.Abort();
            }

            if (MultithreadedSend)
            {
                sendThread.Abort();
            }

            SocketUtilities.CloseSocket(Socket);
        }
        protected override void ConnectInternal(IPEndPoint EndPoint)
        {
            Socket.Connect(EndPoint);

            if (FindOptimumMTU)
            {
                MTU = SocketUtilities.FindOptimumMTU(EndPoint.Address, 1000, Constants.UDP.MAX_MTU);
            }

            BufferStream buffer = Packet.CreateHandshakeBufferStream(MTU);

            SendInternal(buffer);

            RunReceiveThread();
            RunSenndThread();
        }
Пример #9
0
 public void Bind(string Host, ushort Port)
 {
     Bind(SocketUtilities.ResolveDomain(Host), Port);
 }
Пример #10
0
 public void Connect(string Host, ushort Port)
 {
     Connect(SocketUtilities.ResolveDomain(Host), Port);
 }
Пример #11
0
 public static void OpenDynamicTCPPorts(ushort From = 1500, ushort Count = 63000)
 {
     SocketUtilities.OpenDynamicTCPPorts(From, Count);
 }
Пример #12
0
        protected override void CloseClientConnection(Client Client)
        {
            base.CloseClientConnection(Client);

            SocketUtilities.CloseSocket(((TCPClient)Client).Socket);
        }