using System.Net.Sockets;
public class SynchronousSocketClient
public static void StartClient()
byte[] bytes = new byte[1024];
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[1];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 1234);
Socket sender = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
sender.Connect(remoteEP);
Console.WriteLine("Socket bağlandı {0}",
sender.RemoteEndPoint.ToString());
int bytesRec = sender.Receive(bytes);
Encoding.ASCII.GetString(bytes, 0, bytesRec));
catch (ArgumentNullException ane)
Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
catch (SocketException se)
Console.WriteLine("SocketException : {0}", se.ToString());
Console.WriteLine("Unexpected exception : {0}", e.ToString());
Console.WriteLine(e.ToString());
public static int Main(String[] args)