BinaryProtocolClient.cpp

См. документацию.
00001 /*
00002  * BinaryProtocolClient.cpp
00003  *
00004  *  Created on: 25.05.2011
00005  *      Author: nick
00006  */
00007 
00008 #include "BinaryProtocolClient.h"
00009 
00010 void* bin_client_threadFunc(void* clnt){
00011         BinaryProtocol* cl= static_cast<BinaryProtocol*> (clnt);
00012         cl->parse();
00013         return NULL;
00014 }
00015 
00016 void BinaryProtocolClient::connect_server(string address, unsigned short port){
00017     struct sockaddr_in stSockAddr;
00018     int i32Res;
00019     skt_id = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP );
00020     if ( skt_id == -1 ){
00021         cout<< "Ошибка: невозможно создать сокет"<<endl;
00022         exit( EXIT_FAILURE );
00023     }
00024 
00025     memset( &stSockAddr, 0, sizeof( stSockAddr ) );
00026 
00027     stSockAddr.sin_family = PF_INET;
00028     stSockAddr.sin_port = htons(port);
00029     i32Res = inet_pton( PF_INET, address.data(), &stSockAddr.sin_addr );
00030 
00031     if ( i32Res < 0 ){
00032         cout<< "Ошибка: первый параметр не относится к категории корректных адресов"<<endl;
00033         close( skt_id );
00034         exit( EXIT_FAILURE );
00035     }else
00036       if ( !i32Res ){
00037           cout<< ( "Ошибка: второй параметр не содержит корректного IP-адреса" );
00038           close( skt_id );
00039           exit( EXIT_FAILURE );
00040       }
00041 
00042     if (connect(skt_id,( const sockaddr* )&stSockAddr, sizeof( stSockAddr )) == -1){
00043         cout<<"Ошибка соединения"<<endl;
00044         close( skt_id );
00045         exit( EXIT_FAILURE );
00046     }
00047     //parserCreate(skt_id);
00048     //curNodeSend=new Node("stream:stream",NULL);
00049     pthread_create(&clientThread,NULL,bin_client_threadFunc,this);
00050     //Создаем и отправляем начальную ноду
00051     //createNodeSend();
00052     /* выполнение операций чтения и записи ... */
00053     //shutdown( i32SocketFD, SHUT_RDWR );
00054     //close( i32SocketFD );
00055 }
00056 
00057 BinaryProtocolClient::BinaryProtocolClient(ClientConfigFile* cf):BinaryProtocol(cf) {
00058         // TODO Auto-generated constructor stub
00059 
00060 }
00061 
00062 BinaryProtocolClient::~BinaryProtocolClient() {
00063         // TODO Auto-generated destructor stub
00064 }