[Mono-dev] Async socket connection problem on FreeBSD

Alex Chudnovsky alexc at majestic12.co.uk
Sat Feb 11 09:40:42 EST 2006


Hi all,

Apologies for not posting to FreeBSD specific list but my attempts to 
subscribe to it did not seem to have succeeded.

The test case below is for an issue on Mono v1.1.12 running on FreeBSD - 
basically if asyncronous socket connection is being made then it never 
succeeds - it just hangs out there and callback never happens. 
Syncronous version of connect works fine - in the test case by default 
async connection will be attempted but if any command line arguements 
used then syncronous will be done.

Any ideas would be appreciated.

/* ************************************************************ */
using System;
using System.Net;
using System.Net.Sockets;

namespace Majestic12
{
    /// <summary>
    /// SocketTest: test of socket connection failure on Mono running on 
FreeBSD
    /// </summary>
    class SocketTest
    {

        [STAThread]
        static void Main(string[] args)
        {
            bool bUseAsync=true;

            if(args.Length==0)
                Console.WriteLine("No params detected, will use ASYNC 
socket operation, put anything to make it use SYNCronous request");
            else
                  bUseAsync=false;


            // known high-uptime host: www.bbc.co.uk
            string sIP="212.58.224.125";
            int iPort=80;

            SocketTest oST=new SocketTest();
            oST.Start(sIP,iPort,bUseAsync);
        }

        Socket oConn=null;

        void Start(string sIP,int iPort,bool bUseAsync)
        {
            Console.WriteLine("Trying to connect to {0}:{1} using {2} 
IO",sIP,iPort,bUseAsync ? "ASYNCronous" : "SYNCronous");

            IPEndPoint oEP=new IPEndPoint(IPAddress.Parse(sIP),iPort);

            oConn=new 
Socket(oEP.Address.AddressFamily,SocketType.Stream,ProtocolType.Tcp);

            if(bUseAsync)
                oConn.BeginConnect(oEP,new AsyncCallback(EndConnect),this);
            else
            {
                oConn.Connect(oEP);
                Console.WriteLine("SYNC IO successfully worked!");
            }

            Console.WriteLine("Press ENTER to exit - if you used ASYNC 
IO then wait for callback confirmation");
            Console.ReadLine();
        }

        /// <summary>
        /// This function will be called when using AsyncIO
        /// </summary>
        void EndConnect(IAsyncResult oAR)
        {
            Console.WriteLine("ASYNC EndConnect callback received!");

            try
            {
                SocketTest oThis=(SocketTest) oAR.AsyncState;

                oThis.oConn.EndConnect(oAR);
            }
            catch(SocketException oEx)
            {
                Console.WriteLine("SOCKET ERROR: "+oEx.ToString());
            }
            catch(Exception oEx)
            {
                Console.WriteLine("GENERAL ERROR: "+oEx.ToString());
            }
        }
    }
}






More information about the Mono-devel-list mailing list