Example #1
0
int main()
{	
	int 		ret = 0;
	void 		*handle = NULL;
	//void 		handle = NULL;
	int 		connfd;
	
		
	 unsigned char *data = (unsigned char *)"aaaaaafffffffffffssssss";
	 int 		datalen = 10;
	 
	 unsigned char out[1024];
	 int outlen = 1024;
	//客户端环境初始化
	//int sckCliet_init(void **handle, char *ip, int port, int contime, int sendtime, int revtime);
	ret = sckCliet_init(&handle, 15, 5, 5, 10);
	
	ret = sckCliet_getconn(handle, "127.0.0.1", 8001, &connfd);
	//客户端发送报文
	ret = sckClient_send(handle,  connfd, data, datalen);
	
	
	//客户端端接受报文
	ret = sckClient_rev(handle, connfd, out, &outlen);
	
	
	// 客户端环境释放 
	ret = sckClient_destroy(handle);

}
int main(void)
{
	void *handle = NULL;	
	int connfd = 0;
	char *data = "linux is very good!";

	int ret = sckClient_init(&handle, 30, 30, 30, 10);
	if (0 != ret) {
		printf("Init error code %d.\n", ret);
		return ret;
	}

	ret = sckClient_getconn(handle, SERVER_IP, SERVER_PORT, &connfd);
	if (0 != ret) {
		printf("Getconn error code %d.\n", ret);
		perror("Getconn error");
		return ret;
	}

	ret = sckClient_send(handle, connfd, (unsigned char *)data, strlen(data));
	if (ret < 0) {
		perror("Send error");
		return ret;
	}
	unsigned char buffer[RECV_BUFFER_SIZE] = {0};
	ret = sckClient_recv(handle, connfd, buffer, sizeof(buffer));
	if (ret < 0) {
		perror("Recvie error:\n");
		return ret;
	}
	printf("recv....%s.\n", buffer);

	sckClient_closeconn(&connfd);

	sckClient_destory(&handle);

	return 0;
}