onreceive

阅读 / 问答 / 标签

请问CSocket 类中的 OnReceive()的参数

CAsyncSocket::OnReceiveCalled by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function.virtual void OnReceive( int nErrorCode );ParametersnErrorCode The most recent error on a socket. The following error codes apply to the OnReceive member function: 0 The function executed successfully. WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed. RemarksFor more information, see Windows Sockets: Socket Notifications.Examplevoid CMyAsyncSocket::OnReceive(int nErrorCode) // CMyAsyncSocket is // derived from CAsyncSocket{ static int i=0; i++; TCHAR buff[4096]; int nRead; nRead = Receive(buff, 4096); switch (nRead) { case 0: Close(); break; case SOCKET_ERROR: if (GetLastError() != WSAEWOULDBLOCK) { AfxMessageBox ("Error occurred"); Close(); } break; default: buff[nRead] = 0; //terminate the string CString szTemp(buff); m_strRecv += szTemp; // m_strRecv is a CString declared // in CMyAsyncSocket if (szTemp.CompareNoCase("bye") == 0 ) ShutDown(); } CAsyncSocket::OnReceive(nErrorCode);}

MFC SOCKET 网络编程--OnReceive函数无法响应,为什么???

CliSock.Create(0,SOCK_STREAM,FD_CONNECT|FD_READ);

android 中AlarmReceiver的onReceive怎样开启一个activity

可以的啊 Intent 跳转就是啊

MFC 中CAsyncSocket类的OnReceive(); OnConnect() ;OnClose() 改写

在Win32的库里用WSASocket创建SOCKETWSACreateEvent创建一个WSAEvent,使用WSAEventSelect注册感兴趣的事件(FD_READ|FD_CONNECT|FD_CLOSE)使用WSAWaitForMultipleEvents等待WSAEvent(可以另起一线程)使用WSAEnumNetworkEvents获取相关SOCKET上发生了什么,并对应进行处理(将原来的OnReceive(); OnConnect() ;OnClose()实现去掉MFC特有的代码)

自己定义的CSocket的类中的OnReceive函数不被触发

服务端有调用CSocket::Receive吗?

Android中定义了一个接收短信的广播类,但是里面的OnReceive方法始终没有执行,求解

虽然我眼拙没有看出什么不对劲,网上博文写的基本也如此,但也有点心得:从短信接收后系统发出广播,虽然是异步广播,但是实际上到你写的接收器接收到并处理之间可能会有一段较长的时间,可能是几秒;先检查接收器是否注册成功。

mfc CSocket::OnReceive 接收不到

要把socket设为允许读才可以。

MFC CSocket::OnReceive()函数不被触发?

ActiveX控件用于Web的过程是将控件嵌入主页中,用户通过浏览器访问该主页时,将主页中的控件下载,并在用户机器上注册,以后就可在用户的浏览器上运行。控件下载一次后就驻留在用户本地机器上,下次再访问相同的主页时,可不再下载该控件,而是直接运行用户本地的控件。这里控件容器就是浏览器,用户不需要通过浏览器调用控件的属性或方法。因此,开发面向Web的ActiveX控件比开发桌面的控件还要简单些,所复杂的是如何将该控件很好地嵌入主页,使用户能正常浏览。

MFC中使用cncomm类,无法响应OnReceive

2

请问,关于安卓广播接收者的问题,安卓中onReceive方法中的参数context和intent

context是上下文环境,一般是说明你这个在哪个包里面进行的活动还有加载资源值也要用到,你可以先记住有这么一个东西,intent用于页面跳转可指定包名显式跳转,也可以设定参数进行隐式跳转,多用用就知道了,建议自己手打不要光看书

CAsyncSocket::OnReceive怎么用

重载CAsyncSocket::OnReceive添加代码char buf[10];int len=receive(buf,10);if(len>0){//你想扎存那就存那}

onReceive(Context context, Intent intent)方法的两个参数是什么意思?

收到context,执行intent。

请问CSocket 类中的 OnReceive()的参数

CAsyncSocket::OnReceiveCalled by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function.virtual void OnReceive( int nErrorCode );ParametersnErrorCode The most recent error on a socket. The following error codes apply to the OnReceive member function: 0 The function executed successfully. WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed. RemarksFor more information, see Windows Sockets: Socket Notifications.Examplevoid CMyAsyncSocket::OnReceive(int nErrorCode) // CMyAsyncSocket is // derived from CAsyncSocket{ static int i=0; i++; TCHAR buff[4096]; int nRead; nRead = Receive(buff, 4096); switch (nRead) { case 0: Close(); break; case SOCKET_ERROR: if (GetLastError() != WSAEWOULDBLOCK) { AfxMessageBox ("Error occurred"); Close(); } break; default: buff[nRead] = 0; //terminate the string CString szTemp(buff); m_strRecv += szTemp; // m_strRecv is a CString declared // in CMyAsyncSocket if (szTemp.CompareNoCase("bye") == 0 ) ShutDown(); } CAsyncSocket::OnReceive(nErrorCode);}由以上可知, 这个参数是输出参数,如果函数成功接收数据,则该参数为0,否则输出为错误代码。能否讲一下什么是函数的输出参数?////////////////////////////////如果说这样的函数:void add(int & value){ value++;}int n = 5;add(n);n就变成6了。///////////////////////////////////////我看错了,呵呵,不是输出参数,因为函数原型是:virtual void OnReceive( int nErrorCode );nErrorCode是int,不是int &或者int *,所以不是输出参数。我查看了一下MSDN和CAsyncSocket的源码://///////////////////////////////////////////////////////////////////////////// CAsyncSocket Overridable callbacksvoid CAsyncSocket::OnReceive(int /*nErrorCode*/){}这个函数什么都没做。我估计当框架接收到数据到来的消息后,就调用CAsyncSocket::OnReceive,而nErrorCode这个参数也是框架自己提供的,表示当前网络的状态。程序员不用管它,只须在自己的socket类中重载该函数,并在函数体内实现自己的接收代码就可以了。

为什么onReceive不会执行呢?

代码好像是没什么问题,不过可以修改一下:public class Test extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { System.out.println("Screen off..................."); } }, filter);}@Overrideprotected void onResume() { super.onResume(); System.out.println("onResume()");}@Overrideprotected void onDestroy() { super.onDestroy(); System.out.println("onDestroy()");}@Overrideprotected void onPause() { super.onPause(); System.out.println("onPause()");}

Android 怎么在onReceive方法中再发一条广播

起一个线程,每发一个广播后就sleep一分钟,如此循环。(或者接受系统的timechanged这个广播,这个广播好像一分钟发一次)。 Android 在发送广播时的方法 sendBroadcast(Intent)。 ①:Intent myIntent = new Intent();——【创建Intent对象】 ②:myIntent.setAction(String)——【设置一般的要执行的动作。参数:动作一个动作的名称,如ACTION_VIEW。应用程序的具体行动,应与供应商的包名作为前缀。】 ③:myIntent.putExtra(String,Object)——【广播中额外发送的数据,String为自定义key,Object表示多种数据类型】 ④:sendBroadcast(myIntent);——【发送广播】接收广播 Android在接收广播的方法是注册一个广播接收器 registerReceiver(MyReceiver,IntentFilter)。 ①:首先创建MyReceiver类(类名自定义) 继承 BroadcastReceiver类。——【创建广播接收器】 ②:在MyReceiver中重写public void onReceive(Context context, Intent intent)方法。这个方法在接收到广播后触发。——【重写处理方法】 ③:在Activity或者Service启动时 onCreate()、onStartCommand()等方法中实例化 MyReceiver类——【启动时实例化广播接收器】 ④:IntentFilter filter = new IntentFilter();——【创建IntentFilter对象 意图过滤器】 ⑤:filter.addAction(String);——【在过滤器中加入过滤条件,说明接收什么广播】 ⑥:registerReceiver(cmdReceiver, filter);——【注册广播,参数为(广播接收器,意图过滤器)】

mfc onreceive

该函数是个需要重载的回调函数,当一个套接口已经准备好数据,并且可以由函数Receive()接收时,就可以调用此函数处理相应的消息。//下面的CMyAsyncSocket是CAsyncSocket类的派生类void CMyAsyncSocket::OnReceive(int nErrorCode){ static int i=0; i++; TCHAR buf[4096]; int nRead; nRead=Receive(buff,4096); switch(nRead) { case 0: Close(); break; case SOCKET_ERROR: if(GetLastError()!=WSAEWOULDBLOCK) { AfxMessageBox("Error occurred"); Close(); } break; default: buff[uRead]=0; CString szTemp(buff); m_strRecv+=szTemp;//m_strRecv是一个在CMyAsyncSocket中说明的字符串 if(szTemp.CompareNoCase("bye")==0) ShutDown(); } CAsyncSocket::OnReceive(nErrorCode);}

OnReceive()怎么用,应写在那里?

CAsyncSocket::OnReceivevirtual void OnReceive( int nErrorCode );ParametersnErrorCodeThe most recent error on a socket. The following error codes apply to the OnReceive member function: 0 The function executed successfully.WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed. RemarksCalled by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function. For more information, see the articleWindows Sockets: Socket Notifications in Visual C++ Programmer"s Guide.Examplevoid CMyAsyncSocket::OnReceive(int nErrorCode) // CMyAsyncSocket is // derived from CAsyncSocket{ static int i=0; i++; TCHAR buff[4096]; int nRead; nRead = Receive(buff, 4096); switch (nRead) { case 0: Close(); break; case SOCKET_ERROR: if (GetLastError() != WSAEWOULDBLOCK) { AfxMessageBox ("Error occurred"); Close(); } break; default: buff[nRead] = 0; //terminate the string CString szTemp(buff); m_strRecv += szTemp; // m_strRecv is a CString declared // in CMyAsyncSocket if (szTemp.CompareNoCase("bye") == 0 ) ShutDown(); } CAsyncSocket::OnReceive(nErrorCode);}