首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Symbian >

用ip跟port连接流媒体服务器(Symbian程序)

2012-12-17 
用ip和port连接流媒体服务器(Symbian程序)void CLeshiEngine::ClientBodyReceived(const TDesC8& aBodyDat

用ip和port连接流媒体服务器(Symbian程序)
void CLeshiEngine::ClientBodyReceived(const TDesC8& aBodyData)
   {
 int i = 0;
 TBuf<300> buf;
 buf.Copy(aBodyData);
 TBuf<15> buf_ss_ip;
 TBuf<10> buf_ss_port;
 TInt pos_ip = 92;
 TInt len_ip = 12;
 TInt pos_port = 116;
 TInt len_port = 5;
 buf_ss_ip = buf.Mid(pos_ip,len_ip);
 buf_ss_port = buf.Mid(pos_port,len_port);
 ShowInfo(buf);
}//这个函数是发送http get请求后返回的数据,buf_ss_ip 和buf_ss_port ,是我提取出的IP地址和端口号,
void CTCPConnection::ConnectL() {
 iClient = ETrue;
    
iHost = CLeshiSettings::Static()->GetTCPHostname();
 iPortNumber = CLeshiSettings::Static()->GetTCPPort();
// if (!CLeshiSettings::Static()->PredefinedServer()) {
// if (!iGui->GetHostPortL(iHost, iPortNumber)) {
// iAborted = ETrue;
// iState = ENotStarted;
// return;
// }

 CLeshiSettings::Static()->SetTCPHostname(iHost);
 CLeshiSettings::Static()->SetTCPPort(iPortNumber);
// }

// TBool useConn = EFalse;
// if (CLeshiSettings::Static()->PredefinedAccessPoint())
// useConn = ETrue;
#ifdef UIQ3
 useConn = ETrue;
#endif

// if (useConn) {
// User::LeaveIfError(iConn.Open(iSocketServer));
// iConnOpened = ETrue;
// iState = EConnectingNet;
// iStatus = KRequestPending;
// if (CLeshiSettings::Static()->PredefinedAccessPoint()) {
// TCommDbConnPref pref;
// pref.SetDirection(ECommDbConnectionDirectionOutgoing);
// pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
// pref.SetIapId(CLeshiSettings::Static()->AccessPointId());
// iConn.Start(pref, iStatus);
// } else {
// iConn.Start(iStatus);
// }
// SetActive();
// } else {
 iState = EConnectingNet;
 iStatus = KErrNone;
 RunL();
// }
}

void CTCPConnection::AcceptL() {
 iClient = EFalse;

 TInt port = CLeshiSettings::Static()->GetTCPPort();
 if (!CLeshiSettings::Static()->PredefinedServer()) {
 if (!iGui->GetPortL(port)) {
 iAborted = ETrue;
 iState = ENotStarted;
 return;
 }
 CLeshiSettings::Static()->SetTCPPort(port);
 }

 iState = EListening;

 User::LeaveIfError(iListenSocket.Open(iSocketServer, KAfInet, KSockStream, KProtocolInetTcp));
 iListenerOpened = ETrue;
 iAddress.SetPort(port);
 User::LeaveIfError(iListenSocket.Bind(iAddress));
 User::LeaveIfError(iListenSocket.Listen(1));
 User::LeaveIfError(iSocket.Open(iSocketServer));
 iSockOpened = ETrue;
 iStatus = KRequestPending;
 iListenSocket.Accept(iSocket, iStatus);
 SetActive();

}
void CTCPConnection::RunL() {

 switch (iState) {
 case EConnectingNet:
 if (iStatus == KErrNone) {
 iState = EResolvingHost;
 iTriedV6 = EFalse;
 TInt err;
 if (iConnOpened)


 err = iResolver.Open(iSocketServer, KAfInet, KProtocolInetUdp, iConn);
 else
 err = iResolver.Open(iSocketServer, KAfInet, KProtocolInetUdp);
 if (err != KErrNone) {
 Abort(err);
 return;
 }
 iResolverOpened = ETrue;
 iResolver.GetByName(iHost, iNameEntry, iStatus);
 SetActive();
 } else if (iStatus == KErrCancel) {
 iAborted = ETrue;
 iState = ENotStarted;
 } else {
 RFileLogger::WriteFormat(_L("debug"), _L("sock.txt"), EFileLoggingModeAppend, _L("connecting net: %d"), iStatus.Int());
 Abort(iStatus.Int());
 return;
 }
 break;
 case EResolvingHost:
 if (iStatus == KErrNone) {
 TInt err;
 if (iConnOpened)
 err = iSocket.Open(iSocketServer, KAfInet, KSockStream, KProtocolInetTcp, iConn);
 else
 err = iSocket.Open(iSocketServer, KAfInet, KSockStream, KProtocolInetTcp);
 if (err != KErrNone) {
 Abort(err);
 return;
 }
 iState = EConnecting;
 iSockOpened = ETrue;
 //iAddress = TInetAddr::Cast(iNameEntry().iAddr);
 //iAddress.SetPort(iPortNumber);
 iAddress.Input(_L("223.4.10.125"));
 iAddress.SetPort(30002);
 iSocket.Connect(iAddress, iStatus);
 SetActive();

 iResolver.Close();
 iResolverOpened = EFalse;
 } else if (iStatus == KErrCancel) {
 iAborted = ETrue;
 iState = ENotStarted;
 } else {
 iResolver.Close();
 iResolverOpened = EFalse;

 RFileLogger::WriteFormat(_L("debug"), _L("sock.txt"), EFileLoggingModeAppend, _L("resolving: %d"), iStatus.Int());
 TInt err = iStatus.Int();
 if (!iTriedV6) {
 err = iResolver.Open(iSocketServer, KAfInet6, KProtocolInetUdp);
 iTriedV6 = ETrue;
 if (err == KErrNone) {
 iResolverOpened = ETrue;
 iResolver.GetByName(iHost, iNameEntry, iStatus);
 SetActive();
 } else {
 RFileLogger::WriteFormat(_L("debug"), _L("sock.txt"), EFileLoggingModeAppend, _L("open v6 resolver: %d"), err);
 err = iStatus.Int();
 }
 }
 if (err != KErrNone) {
 Abort(err);
 }
 }
 break;
 case EConnecting:
 if (iStatus != KErrNone) {
 RFileLogger::WriteFormat(_L("debug"), _L("sock.txt"), EFileLoggingModeAppend, _L("connecting: %d"), iStatus.Int());
 Abort(iStatus.Int());
 return;
 }
 iState = EConnected;
 iReader->Start();
 break;
 case EAborting:
 iAborted = ETrue;
 iState = ENotStarted;
 break;
 case EListening:
 if (iStatus != KErrNone) {
 Abort(iStatus.Int());
 return;
 }
 iState = EConnected;
 iReader->Start();
 iListenSocket.Close();
 iListenerOpened = EFalse;
 break;

 default:
 break;
 }

}


请问,我怎么在ClientBodyReceived()中调用connect()函数去连接呢?,我应该怎么连接服务器,求解答。
[解决办法]
来人啊

热点排行