virtual ~bcoutbuf() { _sock->close(); delete _sock; }
virtual int_type overflow(int_type c) { if (c != traits_type::eof()) { char z(c); _sock->sendBytes(&z, 1); } return c; }
bool TextClientManager::processDeregisterCommand(const std::string &command, const Poco::Net::SocketAddress &address) { char buf[16] = { 0 }; if (sscanf(command.c_str(), "register %s", buf) != 1) { return false; } buf[sizeof(buf)-1] = 0; Poco::Net::DatagramSocket *socket = NULL; if (strcmp("all", buf) == 0) { socket = registerDefault(address); } else { socket = registerClient(atoi(buf), address); } if (socket) { const char *response = "registered"; socket->sendBytes(response, strlen(response)); } return true; }
void Dispatcher::apply( const std::string & source, void * buffer, size_t len) { Rule::Array dests = _rule.parse(source); Poco::Net::DatagramSocket sender; Poco::Logger & logger = Poco::Logger::get("TestLogger"); for (Rule::Array::iterator it = dests.begin(); it != dests.end(); ++it) { Poco::Net::SocketAddress addr(*it); int l = sender.sendTo(buffer, len, addr); assert(l == (int)len); logger.information("from %s to %s %d", source, addr.toString(), l); } // write to file }
RTMFPReceiving::RTMFPReceiving(RTMFPServer& server,Poco::Net::DatagramSocket& socket): Task(server), _server(server),pPacket(NULL),id(0),socket(socket) { int size = socket.receiveFrom(_buff,sizeof(_buff),address); if(_server.isBanned(address.host())) { INFO("Data rejected because client %s is banned",address.host().toString().c_str()); return; } if(size<RTMFP_MIN_PACKET_SIZE) { ERROR("Invalid packet"); return; } pPacket = new PacketReader(_buff,size); id = RTMFP::Unpack(*pPacket); }
void dispatcher_handler(u_char *temp1,const struct pcap_pkthdr *header, const u_char *pkt_data) { u_int i = 0; struct tm *ltime; char timestr[16]; ip_header *ih; udp_header *uh; rtp_header *rh; u_int ip_len; u_short sport, dport; time_t local_tv_sec; int L2Count = 0; for(; L2Count < 16 ; L2Count++) { if(pkt_data[L2Count] == 0x08 && pkt_data[L2Count + 1] == 0x00) { break; } } /* retireve the position of the ip header */ //ih = (ip_header *)(pkt_data + 14); //length of ethernet header 14Byte of L2 ih = (ip_header *)(pkt_data + (L2Count + 2)); //length of ethernet header 14Byte of L2 //printf("proto : %d\n",ih->proto); if (ih->proto == UDP) { static int sendCount = 0; //if(++sendCount > 10) { //usleep(1000); sendCount = 0; } /* retireve the position of the udp header */ ip_len = (ih->ver_ihl & 0xf) * 4; uh = (udp_header *)((u_char*)ih + ip_len); int ret = 0; char *rtp = ((char*)ih + ip_len + 8); int rtp_len = ntohs(uh->len) - 8; rh = (rtp_header *)((u_char*)ih + ip_len + 8); // 视频 { if (ntohs(uh->sport) == 4130 && ntohs(uh->dport) == 5002) // DANBIN m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45250)); if (ntohs(uh->sport) == 10014 && ntohs(uh->dport) == 5002) // FANGWEI //if (ntohs(uh->sport) == 10198 && ntohs(uh->dport) == 45252) // FANGWEI u-law m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45252)); //if (ntohs(uh->sport) == 11782 && ntohs(uh->dport) == 5002) // YILIAN if (ntohs(uh->sport) == 11788 && ntohs(uh->dport) == 45254) // YILIAN m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45254)); if (ntohs(uh->sport) == 8216 && ntohs(uh->dport) == 55456) // RTSP m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45256)); if (ntohs(uh->sport) == 15060 && ntohs(uh->dport) == 31000) // PS m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45258)); if (ntohs(uh->sport) == 5006 && ntohs(uh->dport) == 45252) // CHAOLIU m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45260)); if (ntohs(uh->sport) == 50170 && ntohs(uh->dport) == 45252) // XINGWANG m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45262)); //printf("video seq = %d, udp_len=%d \n", ntohs(rh->seq), rtp_len); } // 音频 { if (ntohs(uh->sport) == 13274 && ntohs(uh->dport) == 5000) // DANBIN m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45251)); if (ntohs(uh->sport) == 10012 && ntohs(uh->dport) == 5000) // FANGWEI //if (ntohs(uh->sport) == 10196 && ntohs(uh->dport) == 45253) // FANGWEI u-law m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45253)); //if (ntohs(uh->sport) == 11780 && ntohs(uh->dport) == 5000) // YILIAN if (ntohs(uh->sport) == 11786 && ntohs(uh->dport) == 45255) // YILIAN m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45255)); if (ntohs(uh->sport) == 5004 && ntohs(uh->dport) == 45253) // CHAOLIU m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45261)); if (ntohs(uh->sport) == 50168 && ntohs(uh->dport) == 45253) // XINGWANG m_ss.sendTo(rtp, rtp_len, Poco::Net::SocketAddress("localhost", 45263)); //printf("audio seq = %d, udp_len=%d \n", ntohs(rh->seq), rtp_len); } } return; }
virtual std::streamsize xsputn(const char *s, std::streamsize num) { _sock->sendBytes(s, num); return num; }