void GateLogic::parseBody( short message_id, std::shared_ptr<EasyBuffer> buf_ptr_, int from_connection_id, int char_id) { const char* c = buf_ptr_->get_buffer(); int size = buf_ptr_->get_size(); switch(message_id){ case msgid::togate::player_login: { gr::Player_Login msg; msg.ParseFromArray(c, size); int char_id = msg.char_id(); int ip = msg.ipv4(); if(isPermited(ip)){ if(isOnline(char_id)){ //删除原来的connection cmp_->remove_from_manager(getConnectionId(char_id)); } //给obj-master发消息 int obj_master = 0; gr::Notify_Obj_Master_Player_Login send_msg; send_msg.set_char_id(char_id); std::shared_ptr<EasyBuffer> buf(new EasyBuffer); int size = send_msg.ByteSize(); buf->prepare(size); send_msg.SerializeToArray(buf->get_buffer(), size); connection_ptr c_p_ = getConnection(obj_master); c_p_->get_io_service().post(boost::bind(&Tcp_Connection::send, c_p_, buf, msgid::fromgate::notify_obj_master_player_login, size)); } break; } case msgid::togate::inter_server_register: { gr::Inter_Server_Register msg; msg.ParseFromArray(c, size); setServerId(msg.server_type(),from_connection_id); std::shared_ptr<EasyBuffer> buf(new EasyBuffer); connection_ptr c_p_ = getConnection(from_connection_id); c_p_->get_io_service().post(boost::bind(&Tcp_Connection::send_to_connection, c_p_, buf, msgid::fromgate::server_registered, 0)); break; } case msgid::togate::transmission: { connection_ptr c_p_ = getConnection(getConnectionId(char_id)); c_p_->get_io_service().post(boost::bind(&Tcp_Connection::send_to_connection, c_p_, buf_ptr_, message_id, buf_ptr_->get_size())); break; } } }
bool SocketSession::deliver(const long fromId, const string message, const int type, const long mid){ LOG_W(fromId, "SocketSession::deliver", type, message); // 国际化 std::string i18nStr(message); LOG_DEBUG("SocketSession::deliver:: msg = "<<message); //cout<<getLang()<<endl; if (pack(getLang(), i18nStr)){ LOG_ERROR("SocketSession::response => I18nTranslate error msg=["<<message.c_str()<<"]"); LOG_W(fromId, "I18n::pack", type, "error"); return false; } MY_INSTANCE(SocketServer).deliverMsg(getConnectionId(), i18nStr ); return 1; }
OsStatus MpRtpInputConnection::setFlowGraph(MpFlowGraphBase* pFlowGraph) { OsStatus stat = MpResource::setFlowGraph(pFlowGraph); // If the parent's call was successful, then call // setFlowGraph on any child resources we have. if(stat == OS_SUCCESS) { if (pFlowGraph != NULL) { mpRtpDispatcher->setNotificationDispatcher(pFlowGraph->getNotificationDispatcher()); if(mpFromNet) { mpFromNet->setFlowGraph(pFlowGraph); } #ifdef INCLUDE_RTCP /* [ */ // Get the RTCP Connection object for this flowgraph connection mpiRTCPConnection = pFlowGraph->getRTCPConnectionPtr(getConnectionId(), 'A', getStreamId()); OsSysLog::add(FAC_MP, PRI_DEBUG, " MpRtpInConn::setFlowGraph(%p) CID=%d, TC=%p", pFlowGraph, getConnectionId(), mpiRTCPConnection); // Let's use the Connection interface to acquire the constituent interfaces // required for dispatching RTP and RTCP packets received from the network as // well as the statistics interface tabulating RTP packets going to the network. INetDispatch *piRTCPDispatch = NULL; IRTPDispatch *piRTPDispatch = NULL; ISetSenderStatistics *piRTPAccumulator = NULL; if(mpiRTCPConnection) { mpiRTCPConnection->GetDispatchInterfaces(&piRTCPDispatch, &piRTPDispatch, &piRTPAccumulator); } // The MprFromNet object needs the RTP and RTCP Dispatch interfaces of the // associated RTCP connection so that RTP and RTCP packets may be forwarded // to the correct location. mpFromNet->setDispatchers(piRTPDispatch, piRTCPDispatch); #endif /* INCLUDE_RTCP ] */ } else { mpRtpDispatcher->setNotificationDispatcher(NULL); } } return stat; }
/*Get the delimited data and save it in a strcture in the memory The data that reaches the client or server is processed in this method */ void processCmd(char *rcvddata,int socket,int bytes_rcvd){ char *ipdata; char *arg; char *iprecdata; char *argz; char *field; int strdlen = strlen(rcvddata); int strreclen ; ipdata =(char *)malloc((strdlen + 1)* sizeof(char)); strcpy(ipdata,rcvddata) ; int count = 0; int idatacnt = 0; char *dataarr[50]; char *tokens[3]; int leng; int ifunction ; int iIndex; int oIndex = 0 ; //char hport[]; int iLoop; //printf("\n Entry point data:%s",ipdata); arg = strtok(ipdata,rdelimiter); while(arg){ //printf("\n Entry point2:%s",arg); if(strcmp(arg,"REG") == 0){ ifunction = REGISTER_CMD ; //clear the list and build new clearClientList(&headClientNode,0); }else if(strcmp(arg,"CON") == 0){ ifunction = CONNECT_CMD ; }else if(strcmp(arg,"UP") == 0){ ifunction = UPLOAD_CMD ; oIndex = 0 ; }else if(strcmp(arg,"DOW") == 0){ ifunction = DOWNLOAD_CMD ; }else if(strcmp(arg,"E1")== 0){ printf("--------File error : File not found at remote peer"); } if(ifunction == CONNECT_CMD && count == 1){ char ips[INET6_ADDRSTRLEN] ; char *rip = ips ; updateConnctdPort(socket,arg,&headConnectdNode,rip); printf("\n-------Connected to Peer :%s",ips); } if(ifunction == UPLOAD_CMD){ strreclen = strlen(arg); dataarr[oIndex] = (char *)malloc((strreclen + 1)* sizeof(char)); strcpy(dataarr[oIndex],arg); //printf("\n Entry point4:%s",dataarr[oIndex]); oIndex++ ; } if(ifunction == DOWNLOAD_CMD){ strreclen = strlen(arg); dataarr[oIndex] = (char *)malloc((strreclen + 1)* sizeof(char)); strcpy(dataarr[oIndex],arg); oIndex++ ; } if(ifunction == REGISTER_CMD ){ strreclen = strlen(arg); //iprecdata = (char *)malloc((strreclen + 1)* sizeof(char)); //strcpy(iprecdata,arg); dataarr[oIndex] = (char *)malloc((strreclen + 1)* sizeof(char)); strcpy(dataarr[oIndex],arg); //printf("\n Entry point4:%s",dataarr[oIndex]); oIndex++ ; } count++ ; arg = strtok(NULL,rdelimiter) ; } if(ifunction == REGISTER_CMD){ for(iLoop = 0;iLoop < oIndex;iLoop++){ //printf("Row data is:%s",dataarr[iLoop]); char *rec = strtok(dataarr[iLoop],fdelimiter); //rec = strtok(dataarr[iLoop],fdelimiter); iIndex = 0 ; while(rec){ tokens[iIndex] = strdup(rec); if(iIndex == 4){ //Call method to add to the clients to server list //printf("\n %s, %s, %s,%s",tokens[0],tokens[1],tokens[2],tokens[3]); addClientstoList(&headClientNode,tokens[0],tokens[1],tokens[2],atoi(tokens[3]),1); } iIndex++ ; rec = strtok(NULL,fdelimiter); } } } if(ifunction == REGISTER_CMD){ listactpeers(0,headClientNode,0); } if(ifunction == UPLOAD_CMD){ //call multiple receive //fileReceive1(dataarr[1],dataarr[2],socket); if(oIndex ==3){ dataarr[oIndex] = (char *)malloc((strreclen + 1)* sizeof(char)); strcpy(dataarr[oIndex],"\0"); } fileReceive(dataarr[1],dataarr[2],dataarr[3],socket,bytes_rcvd); //printf("\n THe sample data is%s :%s :%s",dataarr[1],dataarr[2],dataarr[3]); } if(ifunction == DOWNLOAD_CMD){ int connectId = getConnectionId(socket); int success = 0; success = fileProcess(socket,dataarr[1],connectId); //error in reading file send it to client if(success == 0){ send(socket,"E1@@@E",7,0); } } if(ifunction == CONNECT_CMD){ } }