Skip to content

Instantly share code, notes, and snippets.

@rafacouto
Created April 18, 2015 21:26
Show Gist options
  • Save rafacouto/17d9dfcba3b5d3203b44 to your computer and use it in GitHub Desktop.
Save rafacouto/17d9dfcba3b5d3203b44 to your computer and use it in GitHub Desktop.
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class test
{
public static void Main(String[] args)
{
string hostName = "india.colorado.edu";
int hostPort = 13;
IPAddress ip = Dns.GetHostAddresses(hostName)[0];
IPEndPoint hostep = new IPEndPoint (ip, hostPort);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(hostep);
byte[] bytesReceived = new byte[5 * 1024];
int bytes = sock.Receive(bytesReceived, bytesReceived.Length, 0);
string page = Encoding.ASCII.GetString(bytesReceived, 0, bytes);
Console.WriteLine(page);
sock.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment