public void Run() { user = User.GetUserDetails(); var newConnection = new NetworkListener(); //newConnection.NewConnection += new MainProgram().NewIncomingConnection; //Console.WriteLine("Enter port number to begin listening:"); int portNumber = ExtractPortNumber(ExtractAddress(user.userAddress)); //Display.StatusMessage($"Listening on {portNumber}"); var listenerThread = new Thread(_ => newConnection.StartListening(portNumber)); listenerThread.Start(); var choice = Display.GetInputFromUser("To initiate connection press 'Y/y':"); if (choice.ToLowerInvariant().Equals("y")) { //Console.Clear(); //listenerThread.Interrupt(); //listenerThread.Join(); //newConnection.StopListening(); listenerThread.Suspend(); string peerAddress; peerAddress = Display.GetInputFromUser("Enter peer address to connect:"); NetworkClient networkClient = new NetworkClient(); User peer = new User(peerAddress); Socket socket = networkClient.Connect(ExtractAddress(peerAddress)); Conversation newConversation = new Conversation(); newConversation.StartConversationByClient(socket, user, peer); } Console.ReadKey(true); }
public void Connect() { _listenerSocket = _network.GetSocket(User.IpAddress); try { _network.Connect(_listenerSocket); // Console.WriteLine(" connected to -> {0} ", while (true) { string input; input = Console.ReadLine(); _conversation.SendMessage(_listenerSocket, input); _conversation.ReceiveMessage(_listenerSocket); } // _connection.CloseConnection(_listenerSocket); _listener.StartListening(); } catch { _display.DisplayMessage("Unbale to connect"); } }