问题陈述:
1. 我在windows mobile 6.0 平台上做了个基于连接的UDP客服端,然后向PC上一个UDP服务器发信息,可以发信息到服务器上,但收不到服务器回发的ack.
2. 我做的客服端是绑定了端口18587,但我在服务器的上用抓包工具抓到手机发过来的数据包时,端口号却不是18587,而且会变动!
3. 有没有抓手机的UDP包的方法?
下面的源码:
// udp_client_connect.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <connmgr.h>
#include <connmgr_proxy.h>
#include <Winsock2.h>
#include <stdio.h>
#include <windows.h>
#include <iostream>
#pragma comment (lib,"ws2.lib")
#pragma comment( lib, "cellcore.lib" )
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//建立GPRS连接
GUID IID_DestNetInternet = {0x436ef144, 0xb4fb, 0x4863, 0xa0, 0x41, 0x8f, 0x90, 0x5a, 0x62, 0xc5, 0x72};
CONNMGR_CONNECTIONINFO pConnInfo;
memset(&pConnInfo, 0, sizeof(CONNMGR_CONNECTIONINFO));
pConnInfo.cbSize=sizeof(CONNMGR_CONNECTIONINFO);
pConnInfo.dwParams=CONNMGR_PARAM_GUIDDESTNET;
pConnInfo.dwFlags=CONNMGR_FLAG_PROXY_WAP | CONNMGR_FLAG_PROXY_HTTP | CONNMGR_FLAG_PROXY_SOCKS4 | CONNMGR_FLAG_PROXY_SOCKS5;
pConnInfo.dwPriority=CONNMGR_PRIORITY_USERINTERACTIVE;
pConnInfo.bExclusive=FALSE;
pConnInfo.bDisabled=FALSE;
// pConnInfo.hWnd=m_hWnd;
pConnInfo.guidDestNet= IID_DestNetInternet;
DWORD pdwStatus=0;
HANDLE m_wapHandle;
HRESULT hr=ConnMgrEstablishConnectionSync(&pConnInfo, &m_wapHandle, 10000, &pdwStatus);
printf("ConnMgrEstablishConnectionSync = %d\n",hr);
//1.启动SOCKET库,版本为1.0
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested=MAKEWORD(1,1);
err=WSAStartup(wVersionRequested,&wsaData);
if(err!=0)
{
return 0;
}
if(LOBYTE(wsaData.wVersion)!=1||HIBYTE(wsaData.wVersion)!=1)
{
WSACleanup();
return 0;
}
//创建socket
SOCKET sockClient=socket(AF_INET,SOCK_DGRAM,0); //AF_INET: internetwork: UDP, TCP, etc; SOCK_DGRAM说明是UDP类型
SOCKADDR_IN addrSrv,addrLocal;
//用于循环控制
int flag = 1;
while(flag)
{
char serv_addr[100];
cout << "please input the severaddr : "<<endl;
cin >> serv_addr;
cout<<endl;
addrSrv.sin_addr.S_un.S_addr =inet_addr(serv_addr); //inet_addr()将IP地址从点数格式转换成无符号长整型
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons(18586);
addrLocal.sin_family=AF_INET; //bind to a local port
addrLocal.sin_addr.s_addr=htonl(INADDR_ANY);
addrLocal.sin_port=htons(18587);
//绑定端口
if(bind(sockClient,(struct sockaddr*)&addrLocal,sizeof(struct sockaddr))==-1)
{
printf("error!");
}
//建立连接
if(connect(sockClient,(struct sockaddr*)&addrSrv,sizeof(addrSrv))==-1)
{
printf("error!");
}
struct TRAN_PACKET
{
char buffer[60];