Jump to content

Help with .NET Sockets C#


Wife

Recommended Posts

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);
            }
        }
    }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...