?
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:
?
- //
- Myclass.m
- HyLog01
- //
- Created by Lin Zhihong on 15-6-10.
- Copyright 2015 net Dragon Company. All rights reserved.
- //
- ?
- #import "MyClass.h"
- #import <arpa/inet.h>
- #import <errno.h>
- #import <netdb.h>
- #import <netinet/in .h>
- #import <stdbool.h>
- #import <stdio.h>
- #import <stdlib.h>
- #import <string.h>
- #import <sys/socket.h>
- #import <sys/types.h>
- #import <unistd.h>
- ?
- Static Const in_port_t kportnumber = 11215;
- ?
- @implementation MyClass
- -(void) Getconn
- {
- ???? Const char* hostname = "log.qa.huayu.nd";
- ?
- ???? struct sockaddr_storage* server_addr_ptr;
- ???? struct sockaddr_in* sock_addr_ptr;
- ???? struct sockaddr_storage server_addr;
- ???? struct hostent *host = NULL;
- ?
- ???? Host = Gethostbyname2 (hostname, af_inet);
- ?
- ???? Server_addr_ptr = &server_addr;
- ?
- ???? server_addr.ss_family = host->h_addrtype;
- ???? Sock_addr_ptr = (struct sockaddr_in*) server_addr_ptr;
- ???? Sock_addr_ptr->sin_len = sizeof(*sock_addr_ptr);
- ???? Sock_addr_ptr->sin_port = htons (Kportnumber);
- ???? SOCK_ADDR_PTR->SIN_ADDR = * (struct in_addr*) host->h_addr_list[0];
- ???? memset (&sock_addr_ptr->sin_zero, 0, sizeof(Sock_addr_ptr->sin_zero));
- ???? int sockfd;
- ???? SOCKFD = socket (server_addr.ss_family, sock_stream, 0);
- ???? int err = connect (SOCKFD, (struct sockaddr *) &server_addr, Server_addr.ss_len);
- ???? Const char *bytes = "9996:hello, ios\n";
- ???? Char buffer[30];
- ???? int i;
- ???? for (i = 0; i < i++) {
- ???????? Buffer[i] = bytes[i];
- ????}
- ???? Buffer[i] = ' + ';
- ???? Write (sockfd, buffer, 15);
- ???? Close (SOCKFD);
- ???? NSLog (@ "Conn:%d%d", err, (int)sizeof(buffer));
- ???? //memset (&sock_addr_ptr-
- ???? NSLog (@ "Hello");
- ???? NSLog (@ "send log to Huayu");
- }
- @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