日期:2014-05-19  浏览次数:21083 次

问一个关于socket异步传输中回调函数是怎么一回事?
public   static   bool   WriteDynamicTextToSocket(Socket   s,string   strText,OnSend   OnSendText)
{
byte   []   buf   =   Encoding.UTF8.GetBytes(strText)   ;
int   iLen   =   buf.Length   ;
try
{
WriteDynamicLenToSocket(s,iLen)   ;
return   WriteBufToSocket(s,buf,0,iLen,DEALLEN,OnSendText)   ;
}
catch(Exception   err)
{
MessageBox.Show( "发送文本失败! "+err.Message)   ;
return   false   ;
}
}
public   static   bool   WriteBufToSocket(Socket   s,byte   []   buf,int   iStart,int   iCount,int   iBlock,OnSend   SendSuccess)
{     int   iSended   =   0   ;
int   iSending   =   0   ;
while(iSended <iCount)
{
if   (iSended   +   iBlock   <=   iCount)
iSending   =   iBlock   ;
else
iSending   =   iCount   -   iSended   ;
s.Send(buf,iStart+iSended,iSending,SocketFlags.None)   ;                                            
iSended   +=   iSending   ;
                      if   (ReadResponsionFromSocket(s)== "OK ")
if   (SendSuccess   !=   null)
SendSuccess(iCount,iSended)   ;
                    else
return   false;
}

                  return   true   ;                                              

}
这是一个别人写好的类
我直接调用
baseClass.CommunClass.WriteFileToSocket(socket,SendFileName,得到文本长度的回调函数)

这个不会写了

WriteFileToSocket是一个异步传送的方法,里面要用到回调函数,有谁以前也写的,请帮我看下,我在线的,马上结贴的


}//end   namespace



------解决方案--------------------
http://blog.csdn.net/dahuangcuc/archive/2006/03/18/628121.aspx

------解决方案--------------------
回调函数是一个程序员不能显式调用的函数;通过将回调函数的地址传给调用者从而实现调用.
你把回调函数写好,让其他程序或windows call
------解决方案--------------------
关注.帮顶下...........
------解决方案--------------------
代码太多了!!帮顶!
------解决方案--------------------
关注.帮顶下...........
------解决方案--------------------
异步是你传输数据出去后,你不用管了,由回调函数管,根据回调得到的属性值,在回调函数中处理。至于回调函数得到的属性值是那段数据,你自己标识处理。