using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
IPAddress ip = IPAddress.Parse("192.168.1.2");
TcpListener listener = new TcpListener(ip, 34567);
listener.Start();
Console.WriteLine("Server is running at port 34567");
Console.WriteLine("LocalEndpoint is " + listener.LocalEndpoint);
Socket socket = listener.AcceptSocket();
Console.WriteLine("Connection accepted from " + socket.RemoteEndPoint);
byte[] msg = new byte[100];
int j = socket.Receive(msg);
Console.WriteLine("Receiving...");
for (int i = 0; i <> Console.Write(Convert.ToChar(msg[i])));
ASCIIEncoding enc = new ASCIIEncoding();
socket.Send(enc.GetBytes("Message received"));
Console.WriteLine("\nAcknowledgement sent");
socket.Close();
listener.Stop();
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.WriteLine("\n-- End program --");
Console.ReadLine();
}
}
}