我的世界c语言函数包,C语言发送与接收mcpack

我的世界c语言函数包,C语言发送与接收mcpackintfd 0 fd ul tcpconnect ip port if fd 0 printf connect s d failed ip port return 1 charbuff 65535 10

大家好,欢迎来到IT知识分享网。

int fd  = 0;

fd = ul_tcpconnect(ip,port);

if(fd<=0){

printf(“connect %s:%d:

failed”,ip,port);

return -1;

}

char buff[65535*10];

char tmpbuf[1024*10];

memset(buff,0,sizeof(buff));

memset(tmpbuf,0,sizeof(tmpbuf));

nshead_t *nh =(nshead_t*)(buff);

char *mcbuf =(char *)(nh+1);

int mcbuflen = sizeof(buff)-sizeof(nshead_t);

int ret=0;

mc_pack_t *reqpack = mc_pack_open_w(2

,mcbuf,mcbuflen,tmpbuf,sizeof(tmpbuf));

if( 0 != (ret = MC_PACK_PTR_ERR(reqpack)) ){

printf(“error open

pack\n”);

mc_pack_perror(ret);

}

ret = mc_pack_put_int32(reqpack,

“status”,0);

ret = mc_pack_put_int64(reqpack,

“t_crw_in”,0);

ret = mc_pack_put_int64(reqpack,

“fetchtime”,0);

ret = mc_pack_put_int64(reqpack,

“lastmodified”,0);

ret = mc_pack_put_int64(reqpack, “siteip”,0);

ret = mc_pack_put_str(reqpack, “url”, url);

if(ret < 0)

{

printf(“errr3\n”);

}

ret = mc_pack_put_str(reqpack, “redirected_url”, “”);

ret = mc_pack_put_str(reqpack, “cookie”, “”);

ret = mc_pack_put_str(reqpack, “fetching_info”, “”);

ret = mc_pack_put_str(reqpack, “fetching_info”, “”);

ret = mc_pack_put_str(reqpack, “req_headers”, “”);

ret = mc_pack_put_str(reqpack, “http_header”, “”);

ret = mc_pack_put_str(reqpack, “resp_headers”, “”);

ret = mc_pack_put_str(reqpack, “body”, body);

if(ret < 0)

{

fprintf(stderr, “%s:%d

error!\n”, __FILE__, __LINE__);

}

ret = mc_pack_put_int32(reqpack, “body_size”,

strlen(body));

if(ret < 0)

{

fprintf(stderr, “%s:%d

error!\n”, __FILE__, __LINE__);

}

ret = mc_pack_put_int32(reqpack, “page_len”,

(int)strlen(body));

if(ret < 0)

{

fprintf(stderr, “%s:%d

error!\n”, __FILE__, __LINE__);

}

nh->body_len = mc_pack_get_size(reqpack);

int it_count = mc_pack_get_item_count(reqpack);

strcpy(nh->provider, “zsc”);

mc_pack_close(reqpack);

char tt[1024];

mc_pack_t *testpack =

mc_pack_open_r(mcbuf,mcbuflen,tt,sizeof(tt));

if( 0 != (ret = MC_PACK_PTR_ERR(testpack)) ){

mc_pack_perror(ret);

}

// 通过TCP连接向服务发送请求,并捕获respack返回包

ret = nshead_write(fd,nh,1000);

if(0 != ret)

nshead_error(ret);

if(ret!=0){

printf(“write

err[%m],ret[%d]\n”,ret);

close(fd);

return -1;

}

char resbuff[65535*100];

char tmprbuf[1024*100];

memset(resbuff,0,sizeof resbuff);

memset(tmprbuf,0,sizeof tmprbuf);

nshead_t *nh_res =(nshead_t*)(resbuff);

char *mcrbuf =(char *)(nh_res+1);

int mcrbuflen = sizeof(resbuff)-sizeof(nshead_t);

ret = nshead_read(fd,nh_res,sizeof(resbuff), 1000);

if(ret!=0){

fprintf(stderr, “read

err[%m],ret[%d]\n”,ret);

close(fd);

return -1;

}

mc_pack_t

*respack=mc_pack_open_r(mcrbuf,mcrbuflen,tmprbuf,sizeof(tmprbuf));

it_count = mc_pack_get_item_count(respack);

if(it_count > 0)

{

printPack(respack);

}

close(fd);

mc_pack_close(reqpack);

mc_pack_close(respack);

mc_pack_finish(reqpack);

mc_pack_finish(respack);

return 0;

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/153339.html

(0)
上一篇 2025-03-04 17:00
下一篇 2025-03-04 17:10

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信