Beispiel #1
1
        public SocketServer(int port, ErrorLogger errorLog, FileLogger debugLog)
            : base(errorLog, debugLog)
        {
            try
            {
                this.encoding = Encoding.ASCII;
                this.port = port;
                this.clients = new List<SocketClient>();

                this.listenerLoopThread = new Thread(this.ListenerLoop);
                this.listenerLoopThread.IsBackground = true;
                this.listenerLoopThread.Start();

                this.clientsLoopThread = new Thread(this.ClientsLoop);
                this.clientsLoopThread.IsBackground = true;
                this.clientsLoopThread.Start();

                this.Store("Host.Version", AssemblyInfo.SarVersion);
                this.Store("Host.Port", this.port.ToString());
                this.Store("Host.Clients", this.clients.Count.ToString());
                this.Store("Host.Application.Product", AssemblyInfo.Product);
                this.Store("Host.Application.Version", AssemblyInfo.Version);
            }
            catch (Exception ex)
            {
                this.Log(ex);
            }
        }
Beispiel #2
0
        public SocketClient(SocketServer parent, TcpClient socket, long clientID, ErrorLogger errorLog, FileLogger debugLog)
            : base(errorLog, debugLog)
        {
            try
            {
                this.encoding = Encoding.ASCII;
                this.parent = parent;
                this.ID = clientID;
                this.socket = socket;
                this.stream = this.socket.GetStream();
                this.connected = true;

                this.connectionLoopThread = new Thread(this.ConnectionLoop);
                this.outgoingLoopThread = new Thread(this.OutgoingLoop);
                this.incomingLoopThread = new Thread(this.IncomingLoop);
                this.pingLoopThread = new Thread(this.PingLoop);

                this.connectionLoopThread.IsBackground = true;
                this.outgoingLoopThread.IsBackground = true;
                this.incomingLoopThread.IsBackground = true;
                this.pingLoopThread.IsBackground = true;

                this.Log("Host Constructor");

                this.messagesOut = new List<SocketMessage>();
                this.messagesIn = new List<SocketMessage>();

                // connected
                this.initilized = true;
                this.OnConnectionChange(true);

                this.outgoingLoopThread.Start();
                this.incomingLoopThread.Start();
                this.connectionLoopThread.Start();

                // send clientID
                this.SendData("set", "Me.ID", clientID.ToString(), this.ID);

                // send all values
                lock (parent.MemCache)
                {
                    foreach (KeyValuePair<string, SocketValue> entry in parent.MemCache)
                    {
                        SocketValue val = entry.Value;
                        this.SendValue(entry.Value, this.ID);
                    }
                }

                // send initilization code to client
                this.SendData("startup", this.ID);
            }
            catch (Exception ex)
            {
                this.Log(ex);
            }
        }
Beispiel #3
0
 public SocketMemCache(ErrorLogger errorLog, FileLogger debugLog)
 {
     this.errorLogger = errorLog;
     this.debugLog = debugLog;
 }
Beispiel #4
0
        public SocketClient(string hostname, int port, ErrorLogger errorLog, FileLogger debugLog)
            : base(errorLog, debugLog)
        {
            this.Log("Client Constructor");

            this.encoding = Encoding.ASCII;
            this.parent = null;
            this.hostname = hostname;
            this.port = port;
            this.messagesOut = new List<SocketMessage>();
            this.messagesIn = new List<SocketMessage>();
            this.initilized = false;
            this.connected = false;

            this.connectionLoopThread = new Thread(this.ConnectionLoop);
            this.outgoingLoopThread = new Thread(this.OutgoingLoop);
            this.incomingLoopThread = new Thread(this.IncomingLoop);
            this.pingLoopThread = new Thread(this.PingLoop);

            this.connectionLoopThread.IsBackground = true;
            this.outgoingLoopThread.IsBackground = true;
            this.incomingLoopThread.IsBackground = true;
            this.pingLoopThread.IsBackground = true;

            this.connectionLoopThread.Start();
            this.incomingLoopThread.Start();
            this.outgoingLoopThread.Start();
            this.pingLoopThread.Start();
        }