using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; namespace ServeriTcp { class Program { static byte[] Mesazhi1 { get; set; } static IPEndPoint clientEp { get; set; } public static void Main(string[] args) { //create socket Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sck.Bind(new IPEndPoint(0, 4000)); sck.Listen(100); //accepting connection Socket acc = sck.Accept(); Mesazhi1 = new byte[acc.SendBufferSize]; //accepting the message from client and saveing it to Mesazhi1 int bytesRead = acc.Receive(Mesazhi1); byte[] eDhena = new byte[bytesRead]; //loops through the bytes that were read for (int i = 0; i < bytesRead; i++) { eDhena[i] = Mesazhi1[i]; } string Metoda = Encoding.ASCII.GetString(eDhena); clientEp = (IPEndPoint)acc.RemoteEndPoint; } public static void IPCLIENT() { Console.WriteLine("clients ip address: " + Program.clientEp.Address); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)