Code
using System;
using System.Collections.Generic;
//Networking namespace
using System.Net.Sockets;
//StreamReader namespace
using System.IO;
using System.Text;
namespace CS_Networking_Tutorial
{
class Server
{
static void Main(string[] args)
{
//Create a TcpListener to listen for the client's connection! (Listens on port 100, change to what you want.)
TcpListener Listener = new TcpListener(100);
//Start the server.
Listener.Start();
//Wait for a pending connection
while(true)
{
if (Listener.Pending())
{
//Keep listening until we get a pending connection, then break out of the loop.
break;
}
}
//Create a new TcpClient to accept the connection with
TcpClient Client = Listener.AcceptTcpClient();
//Gets the stream (data stream) from Client into a streamreader
StreamReader Reader = new StreamReader(Client.GetStream());
//Keep reading and displaying data
while (true)
{
try
{
//Read a message from the client
string Msg = Reader.ReadLine();
//Display the message on the console
Console.WriteLine("Received: " + Msg + ".");
}
catch
{
//Couldn't read data; close connection.
Console.WriteLine("Client left!");
Reader.Close();
Client.Close();
Listener.Stop();
break;
}
}
}
}
}Commented the code for ya. If you still have questions just ask through MSN :
[email protected]
OR
post here 😝
I GOT A DOMAIN 😁
yay
