没有合适的资源?快使用搜索试试~ 我知道了~
一个在Linux 下的socket接收文件
资源推荐
资源详情
资源评论
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <iostream>
#include <fcntl.h>
#include <arpa/inet.h>
#include <fstream>
#include <sys/stat.h>
//#include <io.h>
#include <unistd.h>
//#include <alloc.h>
//#include <fcntl.h>
//#include <process.h>
#define SIZE 2048*20
using namespace std;
void *run(void *arg);
int main(void)
{
int fd=0;int res=0;
unsigned int port=6000;
struct sockaddr_in my_addr;
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(port);
my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <iostream>
#include <fcntl.h>
#include <arpa/inet.h>
#include <fstream>
#include <sys/stat.h>
//#include <io.h>
#include <unistd.h>
//#include <alloc.h>
//#include <fcntl.h>
//#include <process.h>
#define SIZE 2048*20
using namespace std;
void *run(void *arg);
int main(void)
{
int fd=0;int res=0;
unsigned int port=6000;
struct sockaddr_in my_addr;
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(port);
my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
fd=socket(AF_INET,SOCK_STREAM,0); //1,create tcp socket
if(fd<0)
{
perror("socket");
exit(-1);
}
cout<<"create socket success,fd:"<<fd<<endl;
res = bind(fd,(struct sockaddr *)&my_addr,sizeof(my_addr)); //2,bind sockfd with sockaddr
if(res!=0)
{
perror("bind");
close(fd);
exit(-1);
}
cout<<"bind success."<<endl;
//3,switch active to unactive
res = listen(fd,10);
if(res!=0)
{
perror("bind");
close(fd);
exit(-1);
}
cout<<"listen success."<<endl;
//4,waiting and accept client connect request...
剩余6页未读,继续阅读
资源评论
u011104864
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功