예제 #1
0
static void* recvDataLoop(void *arg)
{
	StreamSocket *ss =(StreamSocket *)arg;

	if(NULL == ss)
	{
		cerr << "recvDataLoop arg is NULL"<<__LINE__<<endl;
		return NULL;
	}
	cout <<"###@@@enter recvDataLoop@@@@### ip:"<< ss->getRemoteIP()<<":"<< ss->getRemotePort()<<endl;
	StreamSocket sock = StreamSocket(ss->getRemoteSocket(), ss->getRemoteIP(), ss->getRemotePort());

    char buff[RECV_BUFFSIZE];
    int len;

    while(1)
    {
    	len = sock.receive(sock.getRemoteSocket(), buff, sizeof(buff), 45);
    	if(len > 0)
    	{
    		  if(-1 == streamSocketCommandProcess(sock, buff))
				{
					cout<<"\n nsStreamSocketCommandProcess send fail!:"<<endl;
//					break;
				}
    	}
    }

    cerr<<"\n###########@@@@@@@@@ exit @@@@@@@@############### \n";
    sock.close(sock.getRemoteSocket());
    return NULL;
}
 void handle(StreamSocket& sock) override {
     while(true) {
         cout << "handle called.\n";
         string rcvd = sock.receive();
         cout << "received data\n";
         sock.send_all(rcvd);
     }
 }
예제 #3
0
int main() {
    const short port = 5000;

    ServerSocket wsock(5000);

    std::cout << "Listening on port " << port << "\n\n";

    //Serves a single client
    StreamSocket sock = wsock.accept();
    string rcvd;

    do {
        rcvd = sock.receive(1024);
        sock.send_all(rcvd);
    }
    while (rcvd.size() > 0);

    std::cout << "Connection closed" << "\n";

    return 0;
}