Socket.BeginAccept没有调用内部异步回调函数

时间:2012-02-03 16:51:38

标签: sockets callback ethernet

我正在编写一个从IND 560终端读取数据的程序。 IND 560终端是一种称重负载并减轻重量的设备。设备通过以太网连接到PC(10.6.16.166)。以下是我写的代码

 public  Socket m_socListener;
            public AsyncCallback temcallback;
            public void getdata
            {

            m_socListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            IPAddress ipaddress = CreateIPAddress("10.6.16.166");
            IPEndPoint iplocal = new IPEndPoint(ipaddress, 1780);

            m_socListener.Bind(iplocal);

            m_socListener.Listen(4);

            m_socListener.BeginAccept(new AsyncCallback(OnDeviceConnect), m_socListener);
            }

         public void OnDeviceConnect(IAsyncResult async)
    {
        m_socworker = m_socListener.EndAccept(async);
        WaitforWeight(m_socworker); // This is another function 

    }

     public IPAddress CreateIPAddress(string ipadd)
    {
        return IPAddress.Parse(ipadd);
    }


    The Problem here is when I execute the line BeginAccept method it is not calling the function "OnDeviceConnect" just it is executing BeginAccept and stepout to the next line. Am I doing anything wrong in here. Any suggestions would be greatly appreciated

0 个答案:

没有答案