1
0

client.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "log.h"
  2. #include "zio.h"
  3. #include "message_file.h"
  4. #include "thread"
  5. #include "chrono"
  6. int main()
  7. {
  8. int sock=zio::build_stream();
  9. if(zio::connect(sock,"127.0.0.1",9001))
  10. //if(zio::connect(sock,"192.168.8.116",4000))
  11. {
  12. return -1;
  13. }
  14. zio::setiobuf(sock,32<<10,64<<10);
  15. zio::setblocking(sock,false);
  16. int len=1;
  17. int count=0x400+2;
  18. char buf[8192];
  19. uint64_t time;
  20. #if 1
  21. ///socket.io/?EIO=4&transport=websocket&t=1551320786
  22. for(int i=0;i<8000;i++)
  23. {
  24. buf[i]='1';
  25. }
  26. buf[0]=0x04;
  27. buf[1]=0x00;
  28. char recv_buf[8192];
  29. for(;;)
  30. {
  31. while(zio::read(sock,recv_buf,sizeof(recv_buf))>0);
  32. if(count!=zio::writev(sock,buf,count))
  33. break;
  34. }
  35. #else
  36. message_file mf(stdin);
  37. count=0;
  38. uint64_t time_tmp=0;
  39. while(len>0)
  40. {
  41. //while((len=mf.get_line(&time,&buf[count],sizeof(buf)-count)))
  42. {
  43. std_info("......%lu",time);
  44. count+=len;
  45. if(count>1024)
  46. break;
  47. }
  48. len=mf.get_line(&time,&buf[count],sizeof(buf)-count);
  49. if(0==time_tmp)
  50. time_tmp =time;
  51. std::this_thread::sleep_for(std::chrono::milliseconds(time-time_tmp));
  52. log_info("count=%d,time=%llu buf=%s",len,time,buf);
  53. if(count!=zio::writev(sock,buf,count))
  54. break;
  55. count=0;
  56. }
  57. #endif
  58. zio::close(sock);
  59. return 0;
  60. }