public void Connect(IConnection connection, string ip, int port, ISerializer serializer) { if (streamContainer == null) { ArgumentNullException ex = new ArgumentNullException("StreamContainer was not set."); Logger.Instance.WriteLog("Failed at connection: " + ex.ToString()); throw ex; } if (streamContainer.StreamExist("NetworkStream")) { ArgumentException ex = new ArgumentException("Stream already exist."); Logger.Instance.WriteLog("Trying to connect when a stream has already been established."); throw ex; } this.connection = connection; connection.Connect(ip, port); if (connection.fetchStream() == null) { ArgumentNullException ex = new ArgumentNullException("No stream found when fetching."); Logger.Instance.WriteLog("Failed at connection stream retreival: " + ex.ToString()); throw ex; } streamContainer.Add("NetworkStream", connection.fetchStream(), serializer); connection.AddObserver(listener); connection.AddObserver(this); listener.Start(streamContainer.Retrieve("NetworkStream")); }
public ServerChatForm(IConnection conn) { InitializeComponent(); _connection = conn; conn.AddObserver(new ServerChatFormObserver(messageTextBox1)); }