网络编程:从文件传输到协议状态管理
1. 文件传输客户端与服务器
文件传输客户端和服务器的实现是网络编程中的重要部分。客户端的实现相对服务器来说稍简单一些。以下是客户端代码的详细分析:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SERVERPORT 8888
#define MAXBUF 1024
int main(int argc, char* argv[])
{
int sockd;
int counter;
int fd;
struct sockaddr_in xferServer;
char buf[MAXBUF];
int returnStatus;
if (argc < 3)
{
fprintf(stderr, "Usage: %s <ip address> <filename> [dest filename]\n",
argv[0]);
exit(1);
}
/* create a socket */
sockd = so
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



