[清晰理解網際網路絡協議](
[socket程式設計基礎](
using run.bat to run the program
the program is built in visualstudio
type to input
type eof(ctrl+z in windows) to close the program.
@echo on
start server.exe
start client.exe
pause
/*!
* \file client.cpp
* * \author terrytian
* \mail [email protected]
* \date 九月 2016
* *
*/#include
#include
#include
#pragma comment(lib, "ws2_32.lib") //載入 ws2_32.dll
#define buf_size 100
int main() ;
char bufrecv[buf_size] = ;
while (1)
else
//未正確收到輸入
}wsacleanup(); //終止使用 dll
system("pause");
return
0;}
/*!
* \file server.cpp
* * \author terrytian
* \mail [email protected]
* \date 九月 2016
* *
*/#include
#include
#pragma comment (lib, "ws2_32.lib") //載入 ws2_32.dll
#define buf_size 100
int main() ; //緩衝區
while (1)
//關閉套接字
closesocket(servsock);
//終止 dll 的使用
wsacleanup();
return
0;}
本版本主要可實現:在client客戶端選擇等待接受還是傳送訊息的功能。
主要由 老師的版本 遷移過來
attention:
@echo on
start server.exe
start client.exe localhost
pause
#include
#pragma comment(lib, "wsock32.lib")
#include
#include
#define server_port 5432
#define max_bufsize 256
int main(int argc, char * argv)
else
wsareturn = wsastartup(0x101, &wsadata);
if (wsareturn)
/* translate host name into peer's ip address */
hp = gethostbyname(host);
if (!hp)
memset((char *)&sin, 0, sizeof(sin));
memcpy((char *)&sin.sin_addr, hp->h_addr, hp->h_length);
sin.sin_family = af_inet;
sin.sin_port = htons(server_port);
/* active open */
if ((s = socket(pf_inet, sock_stream, 0)) < 0)
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
/* wliu comments: displaying current status */
printf("[******x-talk client] connection to %s is ready\n", host);
printf("[******x-talk client] please input your message (empty input to halt):\n");
/* main loop: get and send lines of text */
while (1)
else
break;
}case
'2':
else
break;
}case
'3':}}
printf("[******x-talk client] connection is terminated\n");
wsacleanup();
return
1;}
#include
#pragma comment(lib, "wsock32.lib")
#include
#include
#define server_port 5432
#define max_pending 5
#define max_bufsize 256
#define max_connection 3
int main()
/* build address data structure */
memset((char *)&sin, 0, sizeof(sin));
sin.sin_family = af_inet;
sin.sin_addr.s_addr = inaddr_any;
sin.sin_port = htons(server_port);
/* setup passive open */
if ((s = socket(pf_inet, sock_stream, 0)) < 0)
if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0)
listen(s, max_pending);
/* wliu comments: displaying current status */
printf("[******x-talk server] server is ready in listening ...\n");
/* wait for connection, then receive and print text */
conn = 0;
while( conn < max_connection )
/* wliu comments: displaying current status */
printf("[******x-talk server] received a connection from %s : \n", inet_ntoa(sin.sin_addr));
//while (len = recv(new_s, buf, sizeof(buf), 0))
else
break;
}case
'2':
else
break;
}case
'3':
default:}}
printf("[******x-talk server] connection from %s is terminated\n", inet_ntoa(sin.sin_addr));
closesocket(new_s);
conn ++;
}printf("[******x-talk server] max_connections achieved, server halt\n");
wsacleanup();
return
1;}
計網習題 第三章作業記錄
幀大於 160 bit 分析 當傳送一幀的時間等於通道傳播延遲的兩倍時,通道利用率為 50 即傳送一幀的時間等於來回路程的傳播延遲時,效率為 50 由於 20ms times 2 40ms,現在傳送速率為 4000bit s。即傳送 1bit 要 0.25ms,40ms 0.25ms bit 160...
5 2 習題(計組)
1,馮諾依曼儲存程式的思想,統一編址,指令和位址平等地位存放在儲存器中 事先約定的入口位址 依靠指令的不同階段來區分指令和資料 2,開中斷 允許中斷 定長的指令週期是由最長的機器週期決定的 每條指令都有取指週期和執行週期,所以必然會訪問記憶體 cpu時鐘週期是最小的單位 空操作指令至少會改變pc的值...
計網 傳輸層
the transport layer 1.功能 1 傳輸層提 用程序之間的邏輯通訊 端到端的通訊 網路層提供的是主機之間的邏輯通訊。從通訊和資訊處理的角度看,傳輸層向它上面的應用層提供通訊服務,它屬於面向通訊部分的最高層,同時也是使用者功能中的最低層。傳輸層位於網路層之上,它為執行在不同主機上的程...