csocket.cpp

来自「linux下的ftp函数库」· C++ 代码 · 共 44 行

CPP
44
字号
#include <stdio.h> 
#include <string.h>
#include <stdlib.h>
#include <errno.h> 
#include <unistd.h>
#include <sys/types.h> 
#include <netinet/in.h> 
#include <sys/socket.h> 
#include <sys/wait.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include "socket.h"
#include "socket.cpp"
/////////////////////////////////////////////////////////////////////////////////////
#define REV_NUM  32
#define SND_NUM  32
//////////////////////////////////////////////////////////////////////////////////////
int main()
{
    char *rev=new char[REV_NUM];//接收缓冲区
    char *send=new char[SND_NUM];//发送缓冲区
    send="dddddsssss";
    
	char ip[32];
	int pt;
	printf("%s:\n","Input IP connected:");
    scanf("%s",ip);
	printf("%s:\n","Input port:");
    scanf("%d",&pt);
	Client_InitSocketsStruct(ip,pt);
    if(Client_CreateConnection()==1)//与远程主机连接成功
	{   //与远程主机的通信协议
		CSendPacket(send,SND_NUM);
        CRecvPacket(rev,REV_NUM);
		printf("receve %s from %s \n",rev,ip);
		sleep(5);
	}
	close(CC_sockfd);
	delete []rev;
	delete []send;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?