Программа просмотра свободного места на жестком диске сервера
Рефераты >> Коммуникации и связь >> Программа просмотра свободного места на жестком диске сервера

lpNumberOfFreeClusters;

p.p.t = space;

p.p.action = 'r';

e = sendto(s_cl, p.buff, sizeof(p)+1,0,(PSOCKADDR)&caddr, sizeof(caddr));

if (e == -1) err("serv info send");

break;

}

tv.tv_sec = 8 * 60;

retval = select(1, &rfds, NULL, NULL, &tv);

}

MessageBox(NULL,"end of serv die to timeout .","tip",MB_OK);

closesocket(s);

SetEvent(finished);

return(1);

}

DWORD WINAPI ThreadAction_cl(LPVOID param) {

memset(&ss,0,sizeof(ss));

union packd p;

char i,k=5;

memset(&p,0,sizeof(p));

struct sockaddr_in addr;

int size = sizeof(addr),tmp,e;

fd_set rfds;

struct timeval tv;

HWND hWnd = HWND(param);

lstrcpy(p.buff,"ppppp");

// CHANGE IP ADDRESS OF SERVER

saddr.sin_addr.s_addr = inet_addr("127.168.86.171");

p.p.action = 'p';

sendto(s, p.buff, sizeof(p)+1,0,(PSOCKADDR)&saddr, sizeof(saddr));

if (e == -1) err("client 1st ping send");

tv.tv_sec = 8;

tv.tv_usec = 0;

int retval;

while (k) {

FD_ZERO(&rfds);

FD_SET(s_cl, &rfds);

retval = select(1, &rfds, NULL, NULL, &tv);

while (retval) {

e = recvfrom(s_cl,p.buff,sizeof(p.buff)+1,0,(sockaddr*)&addr,&size);

alive = true;

saddr.sin_port = htons(SERV_PORT);

switch(p.p.action) {

case('p'):

Sleep(1000);

e = sendto(s, p.buff, sizeof(p)+1,0,(PSOCKADDR)&saddr, sizeof(saddr));

if (e == -1) err("client ping send");

started = true;

break;

case('r'):

space = p.p.t;

for (i=0;i<=4;i++) {

ss[i] = ss[i+1];

};

ss[5]=space;

drawme(hWnd);

trd++;

tr = 0;

break;

}

memset(&p,0,sizeof(p));

k=5; }

p.p.action = 'p';

alive = false;

Sleep(8000);

e = sendto(s, p.buff, sizeof(p)+1,0,(PSOCKADDR)&saddr, sizeof(saddr));

if (e == -1) err("client ping again send");

k--;

}

MessageBox(NULL,"end of client (ie timeout .)","tip",MB_OK);

closesocket(s_cl);

SetEvent(finished);

return(2);

}

DWORD WINAPI ThreadAction_put(LPVOID param) {

union packd pa;

pa.p = ar;

pa.p.action = 'i';

int e,z=5;

tr++;

int k = 5;

while (k) {

k = 5;

while (tr >= trd && k >=0 ) {

if (! iamserv && iamclient) {

saddr.sin_port = htons(SERV_PORT);

e = sendto(s, pa.buff, sizeof(pa.buff)+1, 0,(PSOCKADDR)&saddr, sizeof(saddr));

};

Sleep(1000);

k--;

};

if (!alive) Sleep(8000);

trd = 0; tr = 0; //k--;

if (alive) {

k=5;

}

}

return(5);

}

void drawme(HWND hWnd){

HDC hdc = GetDC(hWnd);

DWORD threadID;

int x,y;

DWORD tm,dig=6844;

char str[12] = "0000000000\0";

for (x = 0 ; x <= 5; x++) {

dig= ss[x];

for (y = sizeof(str); y>0 ;y--){

tm = dig % 10;

dig = int(dig / 10);

str[y-1] = 48 + tm;

}

TextOut(hdc,3, 15 * x,str,sizeof(str));

}

ReleaseDC(hWnd, hdc);

return;

}

void initme(){

s = socket(AF_INET,SOCK_DGRAM,IPPROTO_IP);

saddr.sin_family=AF_INET; /* Target address is IP */

saddr.sin_port=htons(SERV_PORT);

saddr.sin_addr.s_addr = INADDR_ANY;

s_cl = socket(AF_INET,SOCK_DGRAM,IPPROTO_IP);

caddr.sin_family = AF_INET;

caddr.sin_addr.s_addr = INADDR_ANY; //= inet_addr("127.168.86.167");

caddr.sin_port = htons(CLNT_PORT);

}

void startserv(HWND hWnd) {

DWORD threadID;

if (bind(s,(struct sockaddr *)(&saddr),sizeof(saddr))!=0){

MessageBox(NULL,"bind at server error","bind",MB_OK);

};

finished = CreateEvent(NULL,TRUE,FALSE,NULL);

thread = CreateThread(

NULL,65536,ThreadAction_serv,(LPVOID)hWnd,CREATE_SUSPENDED,&threadID

);

ResumeThread(thread);

}

bool clientconnect(HWND hWnd) {

CloseHandle(finished_cl);

DWORD threadID;

int rc = bind(s_cl,(struct sockaddr *)(&caddr),sizeof(caddr));

if ( rc != 0 ) {

// MessageBox(NULL,"bind at client error,rc != 0 ","bind",MB_OK);

// return(false);

}

finished_cl = CreateEvent(NULL,TRUE,FALSE,NULL);

thread_cl = CreateThread(

NULL,65536,ThreadAction_cl,(LPVOID)hWnd,CREATE_SUSPENDED,&threadID

);

ResumeThread(thread_cl);

DWORD threadID2;

finished_put = CreateEvent(NULL,TRUE,FALSE,NULL);

thread_put = CreateThread(

NULL,65536,ThreadAction_put,(LPVOID)hWnd,CREATE_SUSPENDED,&threadID2

);

ResumeThread(thread_put);

return(true);

}

void ServerStop(HWND hWnd) {

CloseHandle(finished);

CloseHandle(finished_draw);

CloseHandle(finished_cl);

CloseHandle(finished_put);

started = false;

closesocket(s);

closesocket(s_cl);

}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,

int nCmdShow){

// TODO: Place code here.

MSG msg;

HACCEL hAccelTable;

// Initialize global strings

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

LoadString(hInstance, IDC_SERVE, szWindowClass, MAX_LOADSTRING);

MyRegisterClass(hInstance);

// Perform application initialization:

if (!InitInstance (hInstance, nCmdShow))

{

return FALSE;

}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SERVE);

while (GetMessage(&msg, NULL, 0, 0)) {

if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

return msg.wParam;

}

//

// FUNCTION: MyRegisterClass()

//

// PURPOSE: Registers the window class.

//

// COMMENTS:

//

// This function and its usage is only necessary if you want this code

// to be compatible with Win32 systems prior to the 'RegisterClassEx'

// function that was added to Windows 95. It is important to call this function

// so that the application will get 'well formed' small icons associated

// with it.

//

ATOM MyRegisterClass(HINSTANCE hInstance)

{

WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;

wcex.lpfnWndProc = (WNDPROC)WndProc;

wcex.cbClsExtra = 0;

wcex.cbWndExtra = 0;

wcex.hInstance = hInstance;

wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SERVE);

wcex.hCursor = LoadCursor(NULL, IDC_ARROW);

wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);

wcex.lpszMenuName = (LPCSTR)IDC_SERVE;

wcex.lpszClassName = szWindowClass;

wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);

}

//

// FUNCTION: InitInstance(HANDLE, int)

//

// PURPOSE: Saves instance handle and creates main window


Страница: