当前位置: 代码迷 >> Symbian >> 关于symbian通过socket发作结构体 有代码
  详细解决方案

关于symbian通过socket发作结构体 有代码

热度:1136   发布时间:2016-04-25 02:28:57.0
关于symbian通过socket发生结构体 有代码
void CTestConnectionAppUi::TCPSendReceiveL()
{
//define the struct which to send
_LIT8(KHTTPGetRequest,"Hello");
Info *iInfo = new Info();


iInfo->bWorkNetName=KHTTPGetRequest;
iInfo->iWorkData = 20;
TPtr8 iBufferPtr(0,0);
iBufferPtr.Set(TPtr8((TUint8*)&iInfo,sizeof(Info)));


//open socket server sessioin
RSocketServ ss;
CleanupClosePushL(ss);
TInt err = ss.Connect();
User::LeaveIfError(err);
//Open connnection on the socket server session
RConnection conn;
CleanupClosePushL(conn);
User::LeaveIfError(conn.Open(ss));
//start the default connection
TRequestStatus status;
conn.Start(status);
//wait for the connection to start
User::WaitForRequest(status);
//Check if start succeed
User::LeaveIfError(status.Int());
//open TCP socket on the started connection
RSocket sock;
CleanupClosePushL(sock);
TInt error;
error = sock.Open(ss,KAfInet,KSockStream,KProtocolInetTcp,conn);
User::LeaveIfError(error);
//Connection to the remote peer(221,208,196,46)
TInetAddr remoteAddr(INET_ADDR(127,0,0,1), 7788);
sock.Connect(remoteAddr,status);
User::WaitForRequest(status);
User::LeaveIfError(status.Int());

/*Now that we are connected,
 * exchange some data...
 * Make a HTTP GET request to the remote peer   
 */
//发送描述符

// _LIT8(KHTTPGetRequest,"Hello");
// sock.Write(KHTTPGetRequest,status);



sock.Write(iBufferPtr,status);

//sock.Write((TDesC8 *)&iInfo,status);
User::WaitForRequest(status);
delete iInfo;
iInfo = NULL;
}
发送字符串的时候就能发出去, 而当发送结构体就会什么也发送不出去,求解
------解决方案--------------------
我都是发生字符串,其实你可以根据某协议(自定义协议)把结构体弄成字符串发生过去,对面接到字符串再还原成结构体就OK了
------解决方案--------------------
引用:
我都是发生字符串,其实你可以根据某协议(自定义协议)把结构体弄成字符串发生过去,对面接到字符串再还原成结构体就OK了

用socket
  相关解决方案