Skip to content

Commit

Permalink
Added custom port selection
Browse files Browse the repository at this point in the history
  • Loading branch information
FelOtt committed Feb 2, 2024
1 parent 86e8a28 commit abd5a44
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions MSG_Client/MSG_Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ static void Main(string[] args)
{
while (true)
{
Console.Write("Enter server IP address or domain, or write exit to close: ");
string serverAddress = Console.ReadLine();
Console.Write("Enter server IP address or domain + port [Format: example.com:1234 or 1.2.3.4:1234], or write exit to close: ");

// Split the input to get the server address and port
string serverAddressInput = Console.ReadLine();
string serverAddress = serverAddressInput.Split(':')[0];
int serverPort = Convert.ToInt32(serverAddressInput.Split(':')[1]);

if(serverAddress == "exit")
if (serverAddress == "exit")
{
break;
}
Expand All @@ -28,7 +32,7 @@ static void Main(string[] args)

try
{
client = new TcpClient(serverAddress, 8888);
client = new TcpClient(serverAddress, serverPort);
clientStream = client.GetStream();

Thread receiveThread = new Thread(new ThreadStart(ReceiveMessages));
Expand Down
Binary file modified MSG_Client/MSG_Client/bin/Release/MSG_Client.exe
Binary file not shown.
Binary file modified MSG_Client/MSG_Client/bin/Release/MSG_Client.pdb
Binary file not shown.
Binary file modified MSG_Client/MSG_Client/obj/Release/MSG_Client.exe
Binary file not shown.
Binary file modified MSG_Client/MSG_Client/obj/Release/MSG_Client.pdb
Binary file not shown.
13 changes: 8 additions & 5 deletions MSG_Sever/MSG_Sever/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ internal class Program
static TcpListener server;
static List<TcpClient> clients = new List<TcpClient>();
static object lockObject = new object();

static int port = 0;
static void Main(string[] args)
{
Console.Title = "Msg_Server by darthmaus";
Console.WriteLine("Press 'Q' to shut down the server.");
Console.Write("Select port to listen on: ");
port = int.Parse(Console.ReadLine());
StartServer();
Thread listenThread = new Thread(new ThreadStart(ListenForClients));
listenThread.Start();
Console.Title = "Msg_Server by darthmaus";
Console.WriteLine("Press 'Q' to shut down the server.");

while (true)
{
if (Console.ReadKey().Key == ConsoleKey.Q)
Expand All @@ -33,9 +36,9 @@ static void Main(string[] args)

static void StartServer()
{
server = new TcpListener(IPAddress.Any, 8888);
server = new TcpListener(IPAddress.Any, port);
server.Start();
Console.WriteLine("Server started on port 8888");
Console.WriteLine($"Server started on port {port}");
}

static void CloseServer()
Expand Down
Binary file modified MSG_Sever/MSG_Sever/bin/Release/MSG_Sever.exe
Binary file not shown.
Binary file modified MSG_Sever/MSG_Sever/bin/Release/MSG_Sever.pdb
Binary file not shown.
Binary file modified MSG_Sever/MSG_Sever/obj/Release/MSG_Sever.exe
Binary file not shown.
Binary file modified MSG_Sever/MSG_Sever/obj/Release/MSG_Sever.pdb
Binary file not shown.

0 comments on commit abd5a44

Please sign in to comment.