91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 21KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-12
  • 語言: C/C++
  • 標簽: Socket??BSD??C??

資源簡介

掌握C語言形式的Socket編程接又用法,能夠正確發送和接收網絡數據包; 分為客戶端和服務端

資源截圖

代碼片段和文件信息

/*socket?tcp客戶端*/
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?

#include?
#include?
#include?
#include?
#include?
#include?
//#include?“public.h“

#define?BUFSIZE?1024
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct?RequestPkt
{
????char?type[5];???//time?name?list?msge?quit
????char?number[3];???//the?order?of?the?client?would?recieve?the?msg
????char?content[800];??//the?content?of?the?target?client?woulf?receive
};

struct?MsgPkt
{
????char?msg;?//$1?/?0
????char?order[3];??//order?of?the?client?who?send?the?msg
????char?IP[20];??????///if?it?is?responsePkt?IP?==?type;?port?==?number;?content?==?content
????char?port[5];
????char?content[800];
};

void?PktRequst(struct?RequestPkt*?t?char*?s);
void?PktMsg(struct?MsgPkt*?t?char*?s);
void?cut(char*?s?char*?tar?int?order)
{
????int?i?=?0;
????int?j?=?0;
????int?k?=?0;
????while(i?!=?order)
????{
????????if(tar[j++]?==?‘$‘)??i++;
????}
????while(tar[j]?!=?‘$‘)
????{
????????s[k++]?=?tar[j++];
????}
????s[k]?=?‘\0‘;
}

void?PktRequst(struct?RequestPkt*?t?char*?s)
{
????strcpy(s?“\0“);
????strcpy(s?“$“);
????strcat(s?t->type);
????if(strcmp(t->type?“msge“)?==?0)
????{
????????strcat(s?“$“);
????????strcat(s?t->number);
????????strcat(s?“$“);
????????strcat(s?t->content);
????}
????strcat(s?“$“);
}

void?unPktReq(char*?s?struct?RequestPkt*?t)
{
????cut(t->type?s?1);
????if(s[1]?==?‘m‘)
????{
????????cut(t->number?s?2);
????????cut(t->content?s?3);
????}
}

void?PktMsg(struct?MsgPkt*?t?char*?s)
{
????strcpy(s?“\0“);
????strcpy(s?“$“);
????s[1]?=?t->msg;
????strcat(s?“$“);
????
????if(t->msg?==?‘1‘?||?t->msg?==?‘3‘)
????{
????????strcat(s?t->order);
????????strcat(s?“$“);
????????strcat(s?t->IP);
????????strcat(s?“$“);
????????strcat(s?t->port);
????????strcat(s?“$“);
????????strcat(s?t->content);
????????strcat(s?“$“);
????}?else
????{
????????strcat(s?“$“);
????????strcat(s?t->IP);
????????strcat(s?“$“);
????????if(strcmp(t->IP?“msge“)?==?0)
????????{
????????????strcat(s?t->port);
????????????strcat(s?“$“);
????????????strcat(s?“$“);
????????}
????????if(strcmp(t->IP?“list“)?==?0)
????????{
????????????strcat(s?t->port);
????????????strcat(s?“$“);
????????????strcat(s?t->content);
????????????strcat(s?“$“);
????????}
????????if(strcmp(t->IP?“name“)?==?0?||?strcmp(t->IP?“time“)?==?0)
????????{
????????????strcat(s?“$“);
????????????strcat(s?t->content);
????????????strcat(s?“$“);
????????}
????}
}

int?unPktMsg(char*?s?struct?MsgPkt*?t)
{
//????if(s[1]?!=?‘1‘)??return?0;
????t->msg?=?s[1];
????cut(t->order?s?2);
????cut(t->port?s?4);
????cut(t->IP?s?3);
????cut(t->content?s?5);
????return?1;
}
?

/////////////////////////////////////////////////////

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-11?14:27??code\
?????文件????????9960??2018-04-11?14:27??code\c.c
?????目錄???????????0??2018-05-14?08:11??__MACOSX\
?????目錄???????????0??2018-05-14?08:11??__MACOSX\code\
?????文件????????2277??2018-04-11?14:27??__MACOSX\code\._c.c
?????文件???????14344??2018-04-08?17:23??code\client
?????文件???????10578??2018-04-11?14:27??code\s.c
?????文件????????3445??2018-04-11?14:27??__MACOSX\code\._s.c
?????文件???????14300??2018-04-08?17:21??code\server

評論

共有 條評論