|
- #include"../tcpSocket/tcpSocket.h"
- #include"../tcpSocket/fileOperation.h"
- //ctrl+k+c
-
- int main()
- {
- init_Socket();
-
- SOCKET serfd = create_serverSocket(); //创建服务器socket
- printf("server has created successfully,waiting for client connect..\n");
- //等待客户端连接
- SOCKET clifd = accept(serfd,NULL,NULL); //创建用于连接的客户端socket
- if (clifd == INVALID_SOCKET) //失败情况
- {
- err("accept");
- }
- printf("客户端发起与服务器的连接,成功...\n");
- //可以与客户端进行通信
- struct MsgHeader msg = { .msgID = MSG_SEND,.fileInfo.fileName = "./AutoHotkey_setup.exe" };
- sendFile(clifd, (char*)&msg); //发送的文件名
-
-
- //if (SOCKET_ERROR == send(clifd, "服务器向客户端发来的消息", 24, 0)) // 字符个数,中文1个汉字=2个字符
- //{
- // err("dingyaya send");
- //}
-
- //char recvBuf[1024] = ""; //定义缓冲区2^10
- //int ret = recv(clifd, recvBuf, 1024, 0); //接收客户端发来的
- //if (ret == 0)
- //{
- // printf("客户端正常下线...\n"); //返回值ret=0客户端正常下线
- //}
- //else if (ret < 0)
- //{
- // err("recv");
- //}
- //puts(recvBuf); //在客户端上显示服务器发送的消息
-
- closesocket(clifd); //系统函数,关闭客户端
- closesocket(serfd);
-
- close_Socket();
- getchar(); //防止闪退
-
- return 0;
- }
|