См. документацию.00001
00002
00003
00004
00005
00006
00007
00008 #include "Client.h"
00009
00010
00011 void Client::connect_server(string address, u_int16_t port){
00012 struct sockaddr_in stSockAddr;
00013 int i32Res;
00014 skt_id = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP );
00015 if ( skt_id == -1 ){
00016 cout<< "Ошибка: невозможно создать сокет"<<endl;
00017 exit( EXIT_FAILURE );
00018 }
00019
00020 memset( &stSockAddr, 0, sizeof( stSockAddr ) );
00021
00022 stSockAddr.sin_family = PF_INET;
00023 stSockAddr.sin_port = htons(port);
00024 i32Res = inet_pton( PF_INET, address.data(), &stSockAddr.sin_addr );
00025
00026 if ( i32Res < 0 ){
00027 cout<< "Ошибка: первый параметр не относится к категории корректных адресов"<<endl;
00028 close( skt_id );
00029 exit( EXIT_FAILURE );
00030 }else
00031 if ( !i32Res ){
00032 cout<< ( "Ошибка: второй параметр не содержит корректного IP-адреса" );
00033 close( skt_id );
00034 exit( EXIT_FAILURE );
00035 }
00036
00037 if (connect(skt_id,( const sockaddr* )&stSockAddr, sizeof( stSockAddr )) == -1){
00038 cout<<"Ошибка соединения"<<endl;
00039 close( skt_id );
00040 exit( EXIT_FAILURE );
00041 }
00042 parserCreate(skt_id);
00043 curNodeSend=new Node("stream:stream",NULL);
00044 pthread_create(&clientThread,NULL,client_threadFunc,this);
00045
00046
00047
00048
00049
00050 }
00051
00052 void Client::createNodeSend(){
00053 #ifdef debug_output
00054 cout<< "====================== START STREAM ===================="<<endl;
00055 #endif
00056 sendNodeStart(*curNodeSend);
00057 }
00058 void* client_threadFunc(void* clnt){
00059 Client* cl= static_cast<Client*> (clnt);
00060 cl->createNodeSend();
00061 cl->startParsing();
00062 return NULL;
00063 }
00064
00065 void Client::startXMLTagNodeHandler(Node* node){
00066 #ifdef debug_output
00067 cout<<"START NODE, RUN THREAD!"<<endl;
00068 #endif
00069
00070 }
00071
00072 void Client::endXMLTagNodeHandler(Node* node){
00073 #ifdef debug_output
00074 cout<< "======================= END STREAM ====================="<<endl;
00075 #endif
00076 sendNodeEnd(*curNodeSend);
00077 delete curNodeSend;
00078 curNodeSend=NULL;
00079 }
00080
00081 Client::Client() {
00082
00083
00084 }
00085
00086
00087 Client::~Client() {
00088
00089 }