È necessario disporre di un cavo di trasferimento dati USB (chiamato anche cavo di collegamento dati USB), che supporto API o SDK, quindi utilizzare il seguente codice:
void usb2usbComm()
{
BYTE buf[65530];
LPU2URET pU2uRet;
BOOL bRet;
int ret;
CString msgstr;
ret = u2u_open();
if (ret == -1){
AfxMessageBox("Open U2U device Success.");
}else{
msgstr.Format("Open U2U device fail,return:%d", ret);
AfxMessageBox(msgstr);
return;
}
//send data
bRet = u2u_SendData(buf, 65530, ret);
if(!bRet)
{
msgstr.Format("Send data error,return:%d", ret);
AfxMessageBox(msgstr);
return;
}
//receive data
while (1){
bRet = u2u_RecvData(recvData, dataLen, ret);
if(!bRet)
{
msgstr.Format("Receive data error,return:%d", ret);
AfxMessageBox(msgstr);
u2u_close();
return;
}else{
break;
}
}
u2u_close();
}
See: Reference1, Reference2
fonte
2013-11-11 06:15:03
Ottimo! Grazie per il suggerimento! – opc0de
l'ho provato (il mio ap utilizza una porta 21121), quindi spengo il wifi sul tablet e apro il mio ap (pc e android che dovrebbero parlare insieme). non lo fanno al momento Socket socket = new Socket (mServerIP, 21121); il socket fallisce IOException – steveh
penso che questo non funzionerà per me perché ho il socket del server sul PC (lo ascolta e accetta) e il socket client su Android. Suppongo che ho bisogno di fare port forwarding su Android? Ho provato un coupé di port forwarders gratuiti ma nessuno ha funzionato. – steveh