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; }
protected override bool HandleSendCommand(SendCommand Command) { if (!SocketUtilities.GetIsReady(Socket)) { return(false); } SendOverSocket(Socket, Command.Buffer); return(true); }
public void Bind(IPEndPoint EndPoint) { if (EndPoint.AddressFamily == AddressFamily.InterNetwork) { EndPoint.Address = SocketUtilities.MapIPv4ToIPv6(EndPoint.Address); } LocalEndPoint = EndPoint; Socket.Bind(EndPoint); }
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(); }
protected void RunReceiveThread() { SocketUtilities.SetSendBufferSize(Socket, SendBufferSize); SocketUtilities.SetReceiveBufferSize(Socket, ReceiveBufferSize); ReceiveBuffer = new byte[ReceiveBufferSize]; if (!MultithreadedReceive) { return; } receiveThread = new Thread(ReceiverWorker); receiveThread.Start(); }
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(); }
public void Bind(string Host, ushort Port) { Bind(SocketUtilities.ResolveDomain(Host), Port); }
public void Connect(string Host, ushort Port) { Connect(SocketUtilities.ResolveDomain(Host), Port); }
public static void OpenDynamicTCPPorts(ushort From = 1500, ushort Count = 63000) { SocketUtilities.OpenDynamicTCPPorts(From, Count); }
protected override void CloseClientConnection(Client Client) { base.CloseClientConnection(Client); SocketUtilities.CloseSocket(((TCPClient)Client).Socket); }