当前位置: 代码迷 >> Symbian >> 请问Symbian下Socket编程
  详细解决方案

请问Symbian下Socket编程

热度:6175   发布时间:2013-02-26 00:00:00.0
请教Symbian下Socket编程!
想编写一个简单的传字符串的Socket程序,如下面代码,运行后,会陷入等待,过会儿客户端出现E32USER_CBase   46,服务器端出现ViewSrv   11   的错误。请大家帮忙解看看什么问题,谢谢!

服务器端:
RSocketServ   ss;
RSocket   listenSocket;
RSocket   serviceSocket;
TRequestStatus   status;

User::LeaveIfError(ss.Connect());
CleanupClosePushL(ss);
User::LeaveIfError(listenSocket.Open(ss,KAfInet,KSockStream,KUndefinedProtocol));
CleanupClosePushL(listenSocket);
User::LeaveIfError(serviceSocket.Open(ss));
CleanupClosePushL(serviceSocket);

TInetAddr   httpAddr(KInetAddrAny,8000);
listenSocket.Bind(httpAddr);

listenSocket.Listen(3);
listenSocket.Accept(serviceSocket,status);
User::WaitForRequest(status);

TBuf8 <60>   buf;
TSockXfrLength   iLen;
serviceSocket.RecvOneOrMore(buf,0,status,iLen);

CleanupStack::PopAndDestroy(3,&ss);

客户端:
RSocketServ   ss;
RSocket   sock;
TRequestStatus   status;
User::LeaveIfError(ss.Connect());
CleanupClosePushL(ss);
User::LeaveIfError(sock.Open(ss,KAfInet,KSockStream,KProtocolInetTcp));
CleanupClosePushL(sock);

TSockAddr   destAddr(KInetAddrLoop);
destAddr.SetFamily(KAfInet);
destAddr.SetPort(8000);
sock.Connect(destAddr,status);

_LIT8(KSendData, "How   are   you! ");
TBufC8 <50>   buf(KSendData);
sock.Send(buf,KSockWriteUrgent,status);
User::WaitForRequest(status);

CleanupStack::PopAndDestroy(2,&ss);

------解决方案--------------------------------------------------------
ViewSrv 11 应该和你贴出来的代码没什么关系吧
应该是ui的错误
KERN-EXEC 3 错误的解释:
This panic is raised when an unhandled exception occurs. Exceptions have many causes, but the most common are access violations caused, for example, by dreferencing NULL. Among other possible causes are: general protection faults, executing an invalid instruction, alignment checks, etc.

你可以调试一下
应该可以查出来的
  相关解决方案