Simple implementation of iOS send probe log to log system

Source: Internet
Author: User

?

By referencing Testin's SDK implementations, we can roughly determine how they are implemented:

?

First, by loading the Testin SDK, and then collecting a variety of 7788 of data, and then sending data to the cloud via the socket.

?

We've got the cloud, that's http://log.qa.huayu.nd:8088.

?

But how to collect data from iOS, we need to write our own SDK,SDK implementation is generally packaged using the framework, but here is basically, I will use a static library to implement, I am here to implement the libhylog01.a

?

To write such a library, you need a Mac that requires the Xcode development environment

?

Create a new static library project with Xcode

?

To create a new class:

MyClass

?

Then, start writing the probe log sending code:

?

  1. //
  2. Myclass.m
  3. HyLog01
  4. //
  5. Created by Lin Zhihong on 15-6-10.
  6. Copyright 2015 net Dragon Company. All rights reserved.
  7. //
  8. ?
  9. #import "MyClass.h"
  10. #import <arpa/inet.h>
  11. #import <errno.h>
  12. #import <netdb.h>
  13. #import <netinet/in .h>
  14. #import <stdbool.h>
  15. #import <stdio.h>
  16. #import <stdlib.h>
  17. #import <string.h>
  18. #import <sys/socket.h>
  19. #import <sys/types.h>
  20. #import <unistd.h>
  21. ?
  22. Static Const in_port_t kportnumber = 11215;
  23. ?
  24. @implementation MyClass
  25. -(void) Getconn
  26. {
  27. ???? Const char* hostname = "log.qa.huayu.nd";
  28. ?
  29. ???? struct sockaddr_storage* server_addr_ptr;
  30. ???? struct sockaddr_in* sock_addr_ptr;
  31. ???? struct sockaddr_storage server_addr;
  32. ???? struct hostent *host = NULL;
  33. ?
  34. ???? Host = Gethostbyname2 (hostname, af_inet);
  35. ?
  36. ???? Server_addr_ptr = &server_addr;
  37. ?
  38. ???? server_addr.ss_family = host->h_addrtype;
  39. ???? Sock_addr_ptr = (struct sockaddr_in*) server_addr_ptr;
  40. ???? Sock_addr_ptr->sin_len = sizeof(*sock_addr_ptr);
  41. ???? Sock_addr_ptr->sin_port = htons (Kportnumber);
  42. ???? SOCK_ADDR_PTR->SIN_ADDR = * (struct in_addr*) host->h_addr_list[0];
  43. ???? memset (&sock_addr_ptr->sin_zero, 0, sizeof(Sock_addr_ptr->sin_zero));
  44. ???? int sockfd;
  45. ???? SOCKFD = socket (server_addr.ss_family, sock_stream, 0);
  46. ???? int err = connect (SOCKFD, (struct sockaddr *) &server_addr, Server_addr.ss_len);
  47. ???? Const char *bytes = "9996:hello, ios\n";
  48. ???? Char buffer[30];
  49. ???? int i;
  50. ???? for (i = 0; i < i++) {
  51. ???????? Buffer[i] = bytes[i];
  52. ????}
  53. ???? Buffer[i] = ' + ';
  54. ???? Write (sockfd, buffer, 15);
  55. ???? Close (SOCKFD);
  56. ???? NSLog (@ "Conn:%d%d", err, (int)sizeof(buffer));
  57. ???? //memset (&sock_addr_ptr-
  58. ???? NSLog (@ "Hello");
  59. ???? NSLog (@ "send log to Huayu");
  60. }
  61. @end

?

Then, start compiling

?

Next, it is referenced in our actual project.

I created a view_switcher project to reference the library I just developed

?

?

Run:

?

Then we can see that our log system server has received the data:

http://log.qa.huayu.nd:8088/

?

Reference documents:

Http://blog.sina.com.cn/s/blog_7b9d64af0101jlym.html

Simple implementation of iOS send probe log to log system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.