但是如何从iOS收集数据呢,我们需要自己写SDK,SDK的实现一般是采用framework来打包,但是这里简单为主,我将使用静态库来实现,我这里实现的是libHyLog01.a
//
// MyClass.m
// HyLog01
//
// Created by 林 志宏 on 15-6-10.
// Copyright 2015年 网龙公司. 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 < 15; i++) {
????????buffer[i] = bytes[i];
????}
????buffer[i] = ‘\0‘;
????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