2

我有MainPage

private void AcceptCallBack(IAsyncResult ar)
{
    try
    {
        ((Service1)ar.AsyncState).EndAccept(ar);
    }
    catch
    {
    }
}

在 service1 中:

private void ReceiveCallBack(IAsyncResult ar)
{
   try
   {
       if (buffer != null)
       {...
           string str = System.Text.UTF8Encoding.UTF8.GetString(buffer);
            strReceive = str;
        }                
       worker.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new  
       AsyncCallback(ReceiveCallBack), worker);
   }
   catch (SocketException)
   {
   }
}

[OperationContract]
public void Accept(string Ip,int Port)
{
    try
    {
       bind and listen....
    }
    catch
    {                
    }
}

private void AcceptCallback(IAsyncResult ar)
{
    try
    {
      ...
        worker.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new      
        AsyncCallback(ReceiveCallBack), worker);
    }
    catch (SocketException)
    {
    }
}

[OperationContract]
public string GetReceiveData()
{                     
    return strReceive;
}

MainPage,我想得到消息,GetReceiveData但我不知道如何。

4

0 回答 0