I am having trouble as I am trying to run my clientsocket.connect until a connection has been established. However it is not running my connect method and I cannot seem to be able to diagnose why that is

 private static ClientSocket clientSocket = new ClientSocket();
        private delegate void connection();

        public Form1()
        {
            InitializeComponent();
            connection waitConnect = callConnect;
            Console.WriteLine("before callconnect invoke");
            IAsyncResult asyncConnect = waitConnect.BeginInvoke(null, null);
            Console.WriteLine("Main method now has control");
            waitConnect.EndInvoke(asyncConnect);
        }



        private void callConnect()
        {
            while (!clientSocket.connected)
            {
                Thread.Sleep(1000);
                Console.WriteLine("still connecting...");
                clientSocket.connect("127.0.0.1", 43);
            }
        }

clientsocket.connected checks a connection has been established.
If more information is needed I can provide.

Thank you

Recommended Answers

All 3 Replies

does this also work if the server isnt running?

use a background worker, Don't use thread.sleep this will hold off your operation.
good luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.