Skip to content

Instantly share code, notes, and snippets.

@abbas-oveissi
Created February 24, 2013 16:05
Show Gist options
  • Save abbas-oveissi/5024344 to your computer and use it in GitHub Desktop.
Save abbas-oveissi/5024344 to your computer and use it in GitHub Desktop.
sample C# code for socket 4
IPAddress ip = IPAddress.Parse("192.168.1.2");
IPEndPoint IpPort = new IPEndPoint(ip, Convert.ToInt32("12345"));
Socket main_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
main_socket.Bind(IpPort);
main_socket.Listen(int.MaxValue);
while (true)
{
Socket client = main_socket.Accept();
byte[] msg = System.Text.Encoding.UTF8.GetBytes("Hi");
client.Send(msg);
client.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment