TCP Socket + UDP Socket
阅读原文时间:2023年07月16日阅读:1

小例子:http://soft.yesky.com/238/2035738.shtml

服务器程序:

#include
#include

#pragma comment(lib, "ws2_32.lib")

using namespace std;

int main ()
{
printf("[SERVER]\n");

int port = ;  
WSADATA wsaData;  
SOCKET sListen, sAccept; //两个socket,一个用于监听,一个用于和client通信  
struct sockaddr\_in serv, client;//两个地址,一个用于自身绑定监听(bind、listen),一个用于记录client的地址

char buf\[\] = "Hello client, This is server!";//准备发送给客户端的信息

if (WSAStartup(MAKEWORD(,),&wsaData)!=)  
{  
    printf("Winsock load failed!\\n");  
    return ;  
}

sListen = socket(AF\_INET, SOCK\_STREAM, );//创建监听socket

if (sListen == INVALID\_SOCKET)  
{  
    printf("socket failed:%d\\n",WSAGetLastError());  
    return ;  
}  
else  
{  
    printf("socket() ok!\\n");  
}

//监听地址设定  
serv.sin\_family = AF\_INET;  
serv.sin\_port = htons(port);  
serv.sin\_addr.s\_addr = htonl(INADDR\_ANY);

if (bind(sListen, (LPSOCKADDR)&serv, sizeof(serv)) == SOCKET\_ERROR)//监听socket和端口绑定  
{  
    printf("bind() failed:%d\\n",WSAGetLastError());  
    return ;  
}  
else  
{  
    printf("bind() ok!\\n");  
}

if (listen(sListen,) == SOCKET\_ERROR)//开始监听  
{  
    printf("listen() failed!\\n");  
    return ;  
}  
else  
{  
    printf("listen() ok!\\n");  
}

int temLen = sizeof(client);

while()  
{  
    sAccept = accept(sListen, (struct sockaddr\*)&client,&temLen);//与客户端建立链接之后创建与之通信的socket,并且将client的地址记录下来

    if (sAccept == INVALID\_SOCKET)  
    {  
        printf("accept() failed:%d\\n",WSAGetLastError());  
        break;  
    }  
    printf("accepted client IP:\[%s\],port\[%d\]\\n",inet\_ntoa(client.sin\_addr),ntohs(client.sin\_port));

    int ret = send(sAccept,buf,sizeof(buf),);  
    if (ret == SOCKET\_ERROR)  
    {  
        printf("send()failed :%d\\n",WSAGetLastError());  
        break;  
    }  
    else  
        printf("send() byte:%d\\n", ret);

    //closesocket(sAccept);  
}  
closesocket(sListen);  
WSACleanup();

return ;  

}

客户端程序:

#include
#include
#pragma comment(lib, "ws2_32.lib")

using namespace std;
int main()
{
WSADATA wsaData;
SOCKET client; //socket
struct sockaddr_in serv;//地址
int port = ; //端口

char buf\[\];            //接受缓存  
memset(buf, , sizeof (buf));

if (WSAStartup(MAKEWORD(,), &wsaData) != )  
{  
    printf("Winsock load failed!\\n");  
    return ;  
}

//server的地址和端口  
serv.sin\_family = AF\_INET;  
serv.sin\_port = htons(port);  
serv.sin\_addr.s\_addr = inet\_addr("192.168.1.100");

client = socket(AF\_INET, SOCK\_STREAM, );//创建socket

if (client == INVALID\_SOCKET)  
{  
    printf("socket() failed:%d\\n",WSAGetLastError());  
    return ;  
}

if (connect(client, (struct sockaddr\*)&serv, sizeof(serv)) == INVALID\_SOCKET)//连接server  
{  
    printf("connect() failed:%d\\n", WSAGetLastError());  
    return ;  
}  
else  
{  
    int ret = recv(client, buf, sizeof(buf), );  
    if (ret == ) return ;  
    else if (ret == SOCKET\_ERROR)  
    {  
        printf("recv()faild:%d\\n",WSAGetLastError());  
        return ;  
    }

    printf("recv() from server:\\n%s\\n",buf);  
    getchar();  
    closesocket(client);  
    WSACleanup();  
}  
return ;  

}

服务器

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY0AAAB+CAIAAABXtNqFAAAbnUlEQVR4nO2daVcbObqA9cumu8NOwpL+FXfmnOmkk/R00pCv99wPdzp7wGBjsxkwazC22TGrWbJgE7ZAE6Yz/yPz4a2SZW2lKpexybzP0UmXVbJKVXY9/UpWCbLtRCaTgY2dnZ2dnZ3d3d3d3d29vb23b9++ffv23bt379+/f//+/YcPH/ZtstlsNpvd1/LBmPc23EuWd068tdmTASe1w8BdgUwmsyVj02bDZp1hzWbVJp1Or9gsLy8vLy8vKVhcXFywmStk1iZlk0wmk8lkIpFIJBIzAnGG6enpNwqmZEwKTKgZHx8fGxsbHR2NxWKxWGx4eHhoaGhwcHBgY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B7N+OolsTZjKWz3DZFfpf/339JAykYqziP8NlWPG4U6XUpTUm9hmtx58/UP5yLTQf3MKoi1MbKo7q/ULlyI/hfNZu7lQc/9KaqpEf8qEUx9RKazrPwpou77+4VR3/OoS8uNwjz9Z7qm3SFVV1XVHomK7PwVHi6Y/Op6iqKLnk2kRBFO52JdYMoD7V1JTpuRQg2kiqycb5678/j9DGbHKcSkVvUtLKBuHd9VzRFW9dSVr66ErP9QZ6dd7KafETyHv1NswdCVKnK0puH9FrGrHV4rA8cfR7+xxRb8QE4Otft/zlfF1snFw4nyFn0f92Tyu5GslDit+vjfOXdodbXk/hfxEKHz9vpJWLB1t7l9p49v1UwhP6BdxG+qPtGn5lP6U3QhH/zAIThwWycZB+3OFh11vs/5X6TH1a+er/HeMVtH6ufdKIlpyGoyetfJ77O6990kuWPy9PQAAVEJfAQCASugrAABQyH9E7xGrParxJAAAAABJRU5ErkJggg==" alt="" />

------------------------------------------------------------------------------Linux 版本

在虚拟中的Ubuntu中测试tcp server和tcp client 总是会有conection refused的问题(即使把所有的防火墙关闭),在windows和虚拟机的Ubuntu之间不论谁是server都可以连通。

server

#include
#include
#include
#include
#include
#include
#include
#include
#include

#define BUFLEN 10

int main(int argc, char **argv)
{
int sockfd, newfd;
struct sockaddr_in s_addr, c_addr;
char buf[BUFLEN];
socklen_t len;
unsigned int port, listnum;

/\*建立socket\*/  
if((sockfd = socket(AF\_INET, SOCK\_STREAM, )) == -){  
      perror("socket");  
      exit(errno);  
}else  
printf("socket create success!\\n");  
/\*设置服务器端口\*/  

// if(argv[2])
// port = atoi(argv[2]);
// else
port = ;
/*设置侦听队列长度*/
if(argv[])
listnum = atoi(argv[]);
else
listnum = ;

/\*设置服务器ip\*/  
memset(&s\_addr,, sizeof(s\_addr));  
s\_addr.sin\_family = AF\_INET;  
s\_addr.sin\_port = htons(port);  
if(argv\[\])  
     s\_addr.sin\_addr.s\_addr = inet\_addr(argv\[\]);  
else  
     s\_addr.sin\_addr.s\_addr = INADDR\_ANY;  

/\*把地址和端口帮定到套接字上\*/  
if((bind(sockfd, (struct sockaddr\*) &s\_addr,sizeof(struct sockaddr))) == -){  
     perror("bind");  
     exit(errno);  
}else  
     printf("bind success!\\n");  

 /\*侦听本地端口\*/  
if(listen(sockfd,listnum) == -){  
     perror("listen");  
     exit(errno);  
}else  
     printf("the server is listening!\\n");  
while(){  
     printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*聊天开始\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n");  
     len = sizeof(struct sockaddr);  
     if((newfd = accept(sockfd,(struct sockaddr\*) &c\_addr, &len)) == -){  
           perror("accept");  
           exit(errno);  
     }else  
           printf("正在与您聊天的客户端是:%s: %d\\n",inet\_ntoa(c\_addr.sin\_addr),ntohs(c\_addr.sin\_port));  
     while(){  
     \_retry:  
           /\*\*\*\*\*\*发送消息\*\*\*\*\*\*\*/  
           bzero(buf,BUFLEN);  
           printf("请输入发送给对方的消息:");  
           /\*fgets函数:从流中读取BUFLEN-1个字符\*/  
           fgets(buf,BUFLEN,stdin);  
           /\*打印发送的消息\*/  
           //fputs(buf,stdout);  
           if(!strncasecmp(buf,"quit",)){  
                printf("server 请求终止聊天!\\n");  
                break;  
           }  
           /\*如果输入的字符串只有"\\n",即回车,那么请重新输入\*/  
           if(!strncmp(buf,"\\n",)){  
                printf("输入的字符只有回车,这个是不正确的!!!\\n");  
                goto \_retry;  
           }  
           /\*如果buf中含有'\\n',那么要用strlen(buf)-1,去掉'\\n'\*/  
           if(strchr(buf,'\\n'))  
               len = send(newfd,buf,strlen(buf)-,);  
           /\*如果buf中没有'\\n',则用buf的真正长度strlen(buf)\*/  
           else  
               len = send(newfd,buf,strlen(buf),);  
           if(len > )  
               printf("消息发送成功,本次共发送的字节数是:%d\\n",len);  
           else{  
                printf("消息发送失败!\\n");  
                break;  
           }  
           /\*\*\*\*\*\*接收消息\*\*\*\*\*\*\*/  
           bzero(buf,BUFLEN);  
           len = recv(newfd,buf,BUFLEN,);  
           if(len > )  
               printf("客户端发来的信息是:%s,共有字节数是: %d\\n",buf,len);  
           else{  
                if(len <  )  
                    printf("接受消息失败!\\n");  
                else  
                    printf("客户端退出了,聊天终止!\\n");  
                break;  
                }  
            }  
       /\*关闭聊天的套接字\*/  
       close(newfd);  
       /\*是否退出服务器\*/  
       printf("服务器是否退出程序:y->是;n->否? ");  
       bzero(buf, BUFLEN);  
       fgets(buf,BUFLEN, stdin);  
            if(!strncasecmp(buf,"y",)){  
           printf("server 退出!\\n");  
           break;  
       }  
  }  
  /\*关闭服务器的套接字\*/  
  close(sockfd);  
  return ;  

}

client:

/*
* tcp client
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include

    #define BUFLEN 10  

    int main(int argc, char \*\*argv)  
    {  
        int sockfd;  
        struct sockaddr\_in server\_addr;  
        socklen\_t len;  
        unsigned int port;  
        char buf\[BUFLEN\];      

        /\*建立socket\*/  
        if((sockfd = socket(AF\_INET, SOCK\_STREAM, )) == -){  
            perror("socket");  
            exit(errno);  
        }else  
            printf("socket create success!\\n");  

        /\*设置服务器端口\*/      

            port = ;  

        /\*设置服务器ip\*/  
        bzero(&server\_addr, sizeof(server\_addr));  
        server\_addr.sin\_family = AF\_INET;  
        server\_addr.sin\_port = htons(port);  
       // if (inet\_aton(argv\[1\], (struct in\_addr \*)&s\_addr.sin\_addr.s\_addr) == 0) {  
        if (inet\_aton("192.168.1.117", (struct in\_addr \*)&server\_addr.sin\_addr.s\_addr) == ) {  
            perror(argv\[\]);  
            exit(errno);  
        }  
        /\*开始连接服务器\*/  
        if(connect(sockfd,(struct sockaddr\*)&server\_addr,sizeof(struct sockaddr)) == -){  
            perror("connect");  
            exit(errno);  
        }else  
            printf("conncet success!\\n");  

        while(){  
            /\*\*\*\*\*\*接收消息\*\*\*\*\*\*\*/  
            bzero(buf,BUFLEN);  
            len = recv(sockfd,buf,BUFLEN,);  
            if(len > )  
                printf("服务器发来的消息是:%s,共有字节数是: %d\\n",buf,len);  
            else{  
                if(len <  )  
                    printf("接受消息失败!\\n");  
                else  
                    printf("服务器退出了,聊天终止!\\n");  
                break;  
            }  
        \_retry:  
            /\*\*\*\*\*\*发送消息\*\*\*\*\*\*\*/  
            bzero(buf,BUFLEN);  
            printf("请输入发送给对方的消息:");  
            /\*fgets函数:从流中读取BUFLEN-1个字符\*/  
            fgets(buf,BUFLEN,stdin);  
            /\*打印发送的消息\*/  
            //fputs(buf,stdout);  
            if(!strncasecmp(buf,"quit",)){  
                printf("client 请求终止聊天!\\n");  
                break;  
            }  
            /\*如果输入的字符串只有"\\n",即回车,那么请重新输入\*/  
            if(!strncmp(buf,"\\n",)){  
                printf("输入的字符只有回车,这个是不正确的!!!\\n");  
                goto \_retry;  
            }  
            /\*如果buf中含有'\\n',那么要用strlen(buf)-1,去掉'\\n'\*/  
            if(strchr(buf,'\\n'))  
                len = send(sockfd,buf,strlen(buf)-,);  
            /\*如果buf中没有'\\n',则用buf的真正长度strlen(buf)\*/  
            else  
                len = send(sockfd,buf,strlen(buf),);  
            if(len > )  
                printf("消息发送成功,本次共发送的字节数是:%d\\n",len);  
            else{  
                printf("消息发送失败!\\n");  
                break;  
            }  
        }  
        /\*关闭连接\*/  
        close(sockfd);  

        return ;  
    }  

注意针对自己的实际情况更改上面的server ip

UDP:

UDP就比较简单了,初始化环境,创建socket和地址 接着: revfrom, sendto就可以了 (server端需要绑定socket和本地地址)

#include
#include
#include
#pragma comment(lib, "ws2_32.lib")

using namespace std;
int main()
{
printf("[server!]\n");

SOCKET sListen;

WSADATA wsaData;

if (WSAStartup(MAKEWORD(,),&wsaData)) //调用Windows Sockets DLL  
{  
    printf("Winsock无法初始化!\\n");  
    WSACleanup();  
    return -;  
}  
printf("服务器开始创建SOCKET...\\n");

struct sockaddr\_in local, from;//2个地址,local是本地地址,from:远端地址

int fromlen =sizeof(from);  
local.sin\_family=AF\_INET;  
local.sin\_port=htons(); ///监听端口  
local.sin\_addr.s\_addr=INADDR\_ANY; ///本机

sListen=socket(AF\_INET,SOCK\_DGRAM,);//数据报, listen socket

if (bind(sListen,(struct sockaddr\*)&local,sizeof(local)) == SOCKET\_ERROR)//监听socket(sListen)和local地址、端口绑定  
{  
    printf("bind() failed:%d\\n",WSAGetLastError());  
    return ;  
} else  
{  
    printf("bind() ok!\\n");  
}

while ()  
{  
    char buffer\[\]="\\0";  
    printf("waiting for message from others-------------\\n");  
    if (recvfrom(sListen,buffer,sizeof(buffer),,(struct sockaddr\*)&from,&fromlen)!=SOCKET\_ERROR)  
    {  
        //recv到远端的: 数据和地址  
        printf("Received datagram from \[%s\]:\[%d\]--%s\\n",inet\_ntoa(from.sin\_addr),ntohs(from.sin\_port),buffer);  
        ////给cilent发信息  
        sendto(sListen,buffer,sizeof(buffer),,(struct sockaddr\*)&from,fromlen);  
    }  
    //Sleep(1000);  
}  
closesocket(sListen);  
WSACleanup();  

}

#include
#include
#pragma comment(lib, "ws2_32.lib")
void main()
{
SOCKET socket1;
//InitWinsock();
WSADATA wsaData;
int iErrorCode;
if (WSAStartup(MAKEWORD(,),&wsaData)) //调用Windows Sockets DLL
{
printf("Winsock无法初始化!\n");
WSACleanup();
return;
}
printf("服务器开始创建SOCKET。\n");
struct sockaddr_in server;
int len =sizeof(server);
server.sin_family=AF_INET;
server.sin_port=htons(); ///server的监听端口
server.sin_addr.s_addr=inet_addr("221.223.16.32"); ///server的地址
socket1=socket(AF_INET,SOCK_DGRAM,);
while ()
{
char buffer[]="\0";
printf("input message\n");
scanf("%s",buffer);
// printf("%s",buffer);
if (strcmp(buffer,"bye")==)
{
printf("退出!\n");
Sleep();
closesocket(socket1);
break;
}
if (sendto(socket1,buffer,sizeof(buffer),,(struct sockaddr*)&server,len)!=SOCKET_ERROR)
{
//printf("sending..\n");
Sleep();
if (recvfrom(socket1,buffer,sizeof(buffer),,(struct sockaddr*)&server,&len) != SOCKET_ERROR)
printf("rece from server:%s\n",buffer);
}
}
closesocket(socket1);
WSACleanup();

}

可参:http://www.cnblogs.com/china-victory/archive/2012/11/06/2757637.html