TCPClient in C# (Error).
Posted
by CSharp
on Stack Overflow
See other posts from Stack Overflow
or by CSharp
Published on 2010-03-11T17:26:22Z
Indexed on
2010/03/11
17:29 UTC
Read the original article
Hit count: 292
using System;
using System.Text;
using System.IO;
using System.Net.Sockets;
namespace ConsoleApp01
{
class Program
{
public static void Main(string[] args)
{
TcpClient client = new TcpClient("python.org",80);
NetworkStream ns = client.GetStream();
StreamWriter sw = new StreamWriter(ns);
sw.Write("HEAD / HTTP/1.1\r\n"
+ "User-Agent: Test\r\n"
+ "Host: www.python.org\r\n"
+ "Connection: Close\r\n");
sw.Flush();
Console.ReadKey(true);
}
}
}
System.Net.Sockets.SocketException: Unable to make a connection because
the target machine actively refused it at System.Net.Sockets.TcpClient..ctor at ConsoleApp01.Program.Main :line 12
Why do i get this error message?
© Stack Overflow or respective owner