bool cudpnet:
:opennet()
// 2.建立監聽套接字
m_socket =::
socket
(af_inet, sock_dgram, ipproto_udp);if
(m_socket == invalid_socket)
// ***************3-28***************=
m_socket_file =::
socket
(af_inet, sock_dgram, ipproto_udp);if
(m_socket_file == invalid_socket)
// ***************3-28***************=
// 3.將監聽套接字與本機進行繫結
sockaddr_in addr_server;
addr_server.sin_family = af_inet;
addr_server.sin_addr.s_un.s_addr = inaddr_any;
// 連線本地任意網絡卡
addr_server.sin_port =
htons
(port);if
(::bind
(m_socket,
(const sockaddr*
)&addr_server,
sizeof
(sockaddr_in)
)== socket_error)
// ********************3-28***************===
sockaddr_in addr_file;
addr_file.sin_family = af_inet;
addr_file.sin_addr.s_un.s_addr = inaddr_any;
// 連線本地任意網絡卡
addr_file.sin_port =
htons
(port+1)
;if(:
:bind
(m_socket_file,
(const sockaddr*
)&addr_file,
sizeof
(sockaddr_in)
)== socket_error)
// ********************3-28***************===
// 4.傳送廣播
bool b_flag = true;if(
setsockopt
(m_socket, sol_socket, so_broadcast,
(const
char*)
&b_flag,
sizeof
(b_flag)
)== socket_error)
// **********3-28 設定為非阻塞的套接字**********===
u_long u_flag =1;
::ioctlsocket
(m_socket, fionbio,
&u_flag);:
:ioctlsocket
(m_socket_file, fionbio,
&u_flag)
;// **********3-28 設定為非阻塞的套接字**********===
// 5.建立執行緒
m_h_thread =
(handle)
_beginthreadex(0
,0,&cudpnet:
:threadproc, this,0,
0);if
(m_h_thread ==0)
return false;
return true;
}
bool cudpnet:
:opennet()
unsigned
int _stdcall cudpnet:
:threadproc
(lpvoid lpvoid)
;// 查詢時間的結構體
timeval tm;
tm.tv_sec =0;
tm.tv_usec =
100;
while
(p_this->m_b_qiut_thread)}}
}return0;
}
#pragma once
// casyncselect 框架
class casyncselect : public cframewnd
return casyncselect:
:m_wnd;
}public:
// 自定義訊息處理函式
afx_msg lresult onasyncselect
(wparam wparam, lparam lparam);}
;
// asyncselect.cpp : 實現檔案
//#include
"stdafx.h"
#include
"feiqproj.h"
#include
"asyncselect.h"
#include
"packdef.h"
// casyncselect
implement_dyncreate
(casyncselect, cframewnd)
casyncselect:
:casyncselect()
casyncselect::~
casyncselect()
begin_message_map
(casyncselect, cframewnd)
end_message_map()
// casyncselect 訊息處理程式
casyncselect* casyncselect:
:m_wnd =
null
;lresult casyncselect:
:onasyncselect
(wparam wparam, lparam lparam)
; sockaddr_in addr_from;
int n_addr_len =
sizeof
(addr_from)
;// 收資料
int n_recv_len =::
recvfrom
(sk, sz_recv_buffer, recv_buffer,0,
(sockaddr*
)&addr_from,
&n_addr_len);if
(n_recv_len >0)
}if(n_network == fd_write)
return0;
}
unsigned
int _stdcall cudpnet:
:threadproc
(lpvoid lpvoid)
; socket socket_arr[2]
=;handle handle_arr[2]
=;while
(p_this->m_b_qiut_thread)}if
(nwe.lnetworkevents == fd_write)
}// ***************===列舉網路事件,判斷發生的事件********************
}return0;
}
作業系統與網路 2019 1 30
void cmodifymemory firstfind dword nfindvalue 6.完成 findonepage 函式,首先用乙個陣列來儲存查詢到的內容 dword sz buffer 1024 7.讀程序位址空間的內容,讀失敗則返回 if 0 readprocessmemory m h...
作業系統與網路 2019 2 1
1.作用域是通過 來進行區分的 2.全域性變數需要使用 來與區域性變數進行區分 同名情況下 3.命名空間是 ansi c 引入的可以由使用者命名的作用域,用來處理程式中常見的同名衝突 4.當只呼叫標頭檔案而沒有開啟命名空間時,某些函式是無法使用的。1.函式的預設值從右到左 右邊有,左邊無 2.函式的...
作業系統與網路 2019 3 18
int main include using namespace std include pragma comment lib,ws2 32.lib intmain if lobyte wsadata.wversion 2 hibyte wsadata.wversion 2 else printf ...