**//
-----------------------自動上報資料-------------------
int__stdcall apientry k1getdata(
long
cbaddress,
inta_localport)
//----------------獲得本地ip-----------------
char
hostname[
255];
myerror
=gethostname(hostname,
sizeof
(hostname));
if(myerror !=0
)
hostent
*myhostent
=gethostbyname(hostname);
if(myhostent
==null)
hostent
&myhost =*
myhostent;
sockaddr_in sa;
for(
intho=0
;myhost.h_addr_list[ho];ho
++)
//----------------綁訂埠-----------------------
//dword l_dwip;
//l_dwip = inet_addr(a_localaddr);
serveraddr.sin_family
=af_inet;
= l_dwip;
serveraddr.sin_addr
=sa.sin_addr;
serveraddr.sin_port
=htons(a_localport);
if(bind(tcpsocket,(sockaddr *)
&serveraddr,
sizeof
(serveraddr))
==socket_error)
//-------------開始偵聽-------------------------
if(listen(tcpsocket,
5)
==socket_error)
dword dwthreadida1;
hthread
=createthread(null,
0,listendata,null,0,
&dwthreadida1);
return
myerror;
}
//------------------幀聽執行緒----------------------
dword __stdcall winapi listendata( lpvoid lpparam )
//------------關閉socket---------------------
closesocket(clientsocket);
closesocket(tcpsocket);
return
0;
}
//------------------接收執行緒----------------------
dword __stdcall winapi acceptdata( lpvoid lpparam )
if(myerror
<=
0)
continue
;
else
break
;
}
//-------------傳送資料----------------------
char
*backbuf
=new
char[75
];
char
*b_mid
=new
char[73
];
char
*b_bcc
=new
char[2
];
memcpy(b_mid,
"back",
4);
memcpy(b_mid +4
,get_buf +4
,69);
getbcc(b_mid,b_bcc,
73);
memcpy(backbuf,b_mid,
73);
//暫時修改成錯誤的。memcpy(backbuf+73,b_bcc,2);
memcpy(backbuf+73
,"aa"
,2);
send(clientsocket,backbuf,75,
0);
//if (bcc1 != null) delete bcc1;
//-------------**函式----------------------
char
recordid[
8];
char
cardid[
6];
char
kqtime[
12];
char
posid[
4];
memcpy(recordid,get_buf +30
,8);
memcpy(cardid,get_buf +38
,6);
memcpy(kqtime,get_buf +44
,12);
memcpy(posid,get_buf +56
,4);
cstring cs_recordid;
cstring cs_cardid;
cstring cs_kqtime;
cstring cs_posid;
for(
intmm=0
;mm<
8;mm
++)
for(intj=
0;j<6;j
++)
for(inti=
0;i<
12;i
++)
for(intm=
0;m<4;m
++)
vbfunc(cs_recordid.allocsysstring(),cs_cardid.allocsysstring(),cs_kqtime.allocsysstring(),cs_posid.allocsysstring());
return
0;
}
//-----------------結束執行緒(關閉幀聽)--------------------
int__stdcall apientry k1closeauto()
ProtoBuf的Socket中應用示例
寫了乙個socket通訊下的protobuf示例,三個檔案 syntax proto3 package demo message helloprotobuf 編譯命令 protoc i cpp out helloprotobuf.proto include include include inclu...
MFC中多執行緒的應用
做專案中涉及到多執行緒的操作,所以學習了一下mfc中多執行緒的用法!包括控制代碼的定義 初始化,執行緒函式的定義 初始化,鎖的使用。控制代碼的定義 cwinthread thread1 執行緒函式的定義 static uint thread1 func lpvoid lpparam 加static表...
MFC中多執行緒的應用
一.使用執行緒步驟 1.定義執行緒函式傳遞引數結構 如 typedef struct tagthreadparms threadparms 2.定義執行緒函式 如 uint read lpvoid pparam 3.啟動執行緒 如 threadparms ptp new threadparms 初始...