예제 #1
0
		public ChatServer(ChatServer.StatusDelegate status)
		{
			Status = status;
			Rooms = new Dictionary<Guid, ChatRoom>();
			Users = new Dictionary<int, User>();
			Active = true;

			#region Trash collector thread
			ThreadStart startCollecting = new ThreadStart(CollectTrash);
			Thread TrashCollector = new Thread(startCollecting);
			TrashCollector.Start();
			#endregion
		}
예제 #2
0
		public User(ChatServer.StatusDelegate status, int usrK, ChatServer server)
		{
			Status = status;
			Server = server;
			UsrK = usrK;

			responseBuilder = new StringBuilder();
			itemCache = new List<ChatItemHolder>();
			lastRequest = DateTime.Now;
			rooms = new Dictionary<Guid, ChatRoom>();

			if (System.Environment.MachineName == "SOLO")
				Online = true;
			else
				Online = false;

			if (System.Environment.MachineName == "SOLO")
				timeoutMins = 1;
			else
				timeoutMins = 15;
		}
예제 #3
0
		public ChatRoom(ChatServer.StatusDelegate status, Guid roomGuid, ChatServer server)
		{
			Server = server;
			Status = status;
			RoomGuid = roomGuid;
			
			lastItemPosted = DateTime.Now;
			lastUserExited = DateTime.Now;

			if (System.Environment.MachineName == "SOLO")
				timeoutMins = 1;
			else
				timeoutMins = 15;

			cacheCapacity = 30;

			users = new Dictionary<int, User>();
			itemCache = new List<ChatItemHolder>();
			responseBuilder = new StringBuilder();

		}
예제 #4
0
        public ServerInstance(int port)
        {

            //_server = ChatServer.Factory(int.Parse(port));

			

			//Set up the channel details
			System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
			provider.TypeFilterLevel = TypeFilterLevel.Full;

			string address = ChatServer.ChatServerIp;// ChatServer.GetMyIP();
			Hashtable props = new Hashtable();
			props.Add("port", port);
			props.Add("bindTo", address);
			props.Add("name", "Address:" + address + ":" + port);//this needs to be unique

			Console.WriteLine("IP: " + address);
			Console.WriteLine("Port: " + port.ToString());

			//Create the channel
			//TcpChannel chan = new TcpChannel(props, null, provider);
			//TcpChannel chan = new TcpChannel(props, null, null);
			//TcpServerChannel chan = new TcpServerChannel(props, null, null);
			TcpServerChannel chan = new TcpServerChannel(props, provider);


			//register it
			ChannelServices.RegisterChannel(chan, false);
			Status("Registered channel", true);

			//register the object as a service
			RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatServer), "Reg", WellKnownObjectMode.Singleton);
			Status("RegisterWellKnownType - Done", true);

			//Don't need this now
			//ChatServer newChatServer = (ChatServer)Activator.GetObject(typeof(ChatServer), "tcp://" + address + ":" + port + "/Reg");
			
			//move this to setup()
			//newChatServer.Setup(port, address);
			//newChatServer.RegisterMyself();
			//newChatServer.RegisterSelfOnDatabase();
			//newChatServer.RegisterOnOtherChatServers();


			_server = new ChatServer(new ChatServer.StatusDelegate(Status));
			RemotingServices.Marshal(_server, "Reg");
			//_server.Setup(port);

            while (true)
            {
                //just stay alive
				//do garbage collection in new thread
                Thread.Sleep(5000);
            }
        }