文件传输案例1.docpiletheserver----puter./puter/fileclientrunstheserverprogram,sIPaddressEnterthefileontheserverthatyouwanttotransfer,accordingtotheprompt・Thisfileisontheserver,srunningdirectoryInrealprogrammingandtesting,puters,puter・Theserver-sideprogramrunsataterminalexecution•/fileserverTheclientprogramrunsandexecutesinanotherterminal/:essitselfvia127・,putertoreplace127・//////////////////////////////////////////////////////////////////////////////////////////>//forsockaddrinincludesys/>//forsocketincludesys/>//>//forprintf#include<>//forexit#include<>//forbzeroincludesys/>includesys/>>>*/#defineFILE_NAME_MAX_SIZE512Intmain(intargc,char**argv){which//setasocketaddressstructure,serveraddr,address,portStructsockaddr_inserver_addr;Bzero(+server_addr,sizeof(server_addr));//setthecontentsofasectionofmemoryareato0Server_add・;(INADDR_ANY);(HELLO_WORLDSERVERPORT);//createaflowprotocol(TCP),anduseserver_sockettorepresenttheserversocketIntserver_socket二socket(,SOCK_STREAM,0):If(server_socket<0){Printf(“CreateSocketFailed!“);Theexit(1);//linkthesocketandsocketaddressstructuresIf(serversocket,(structsockaddr*)andserveraddr,sizeof(serveraddr))Printf(“ServerBindPort:%dFailed!“,HELLO_WORLD_SERVER_PORT);Theexit(1);}//serversocketforlisteningIf(serversocket,LENGTHOFLISTENQUEUE){Printf(“ServerListenFailed!”);Theexit(1);}Thewhile(1)//theserverisrunningallthetime{//hesocketaddressstructureoftheclient,client_addrStructsockaddrinclientaddr;Socklen_tlength二sizeof(clientaddr);//acceptaconnectiontoasocketrepresentedbyserver_socket//ifthereisnoconnectionrequest,thereisaconnectionrequest--eptfunc
文件传输案例1 来自淘豆网m.daumloan.com转载请标明出处.