Ok. Im trying to create a simple TCP Client / Server. The problem I'm having is with !System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it.
My best bet is that the socket listener is not working, but I could not figure out why. Any help is appreciated.
public partial class Primary : Form
{
public static int port = 80;
public static TcpListener listener = new TcpListener(IPAddress.Any, port);
public static Thread conn = new Thread(awaitConnection);
static void awaitConnection()
{
listener.Start();
listener.AcceptSocket();
MessageBox.Show("New Connection received.");
}
public Primary()
{
InitializeComponent();
}
private void Primary_Load(object sender, EventArgs e)
{
conn.Start();
}
private void toolStripStatusLabel1_Click(object sender, EventArgs e)
{
}
}
and
class Program
{
public static TcpClient client;
public static int port = 80; //Connection port
public static string ipaddress = "25.52.118.139"; //Connection IP Address
static void Main(string[] args)
{
client = new TcpClient();
try
{
do
{
client.Connect(IPAddress.Parse(ipaddress), port);
//Establish and maintain connection until it's no longer available.
} while (client.Connected != true);
} catch(Exception err)
{
Console.WriteLine ("Error!" + err);
}
}
}