linux 两次 connect()
来源:互联网 发布:python 方括号 编辑:程序博客网 时间:2024/06/05 21:50
就是有时间研究这个。
一个已经 connect() 成功的 fd 再次 connect 会怎么样呢?撸代码试一下就好了。
#include <sys/types.h>#include <sys/socket.h>#include <errno.h>#include <stdio.h>#include <netinet/in.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>int main(){ const char *addr = "127.0.0.1"; unsigned short port = 6379; struct sockaddr_in sa; int s = -1; if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) { return -1; } sa.sin_family = AF_INET; sa.sin_port = htons(port); if (inet_aton(addr, &sa.sin_addr) == 0) { return -1; } //第一次链接 if (connect(s, (struct sockaddr*)&sa, sizeof(sa)) == -1) { perror("error:"); }else { printf("ok\n"); } //在一次链接 if (connect(s, (struct sockaddr*)&sa, sizeof(sa)) == -1) { printf("errno=%d\n", errno ); perror("error:"); }else { printf("ok\n"); } close( s ); return 0;}
运行结果:
yuhaiyang-Aspire-4750:~/qt/build-doubleConnect-Desktop-Debug$ ./doubleConnect
ok
errno=106
error:: Transport endpoint is already connected
查头文件 errno = 106
#define EISCONN 106 /* Transport endpoint is already connected */
0 0
- linux 两次 connect()
- linux connect mssqlserver
- linux非阻塞connect
- Linux socket connect
- linux connect nonblock
- linux connect 127.0.0.1
- 设置connect超时-linux
- mac connect linux
- Linux connect() timeout
- Linux 非阻塞connect
- linux 设置connect 超时
- linux 非阻塞 connect
- linux connect超时方法
- linux服务器进程为何通常fork()两次
- linux下spring定时器执行两次问题
- Linux--守护进程,为什么要fork两次
- Connect to E680i on linux
- linux connect 设置连接超时
- 3种SAT数学解题方法介绍
- Windows Server2012 虚拟机复制及故障转移(Part3)
- java多线程二
- iOS Xcode工程目录的 folder 和 group的区别(蓝色和黄色文件夹的区别)
- Windows下Eclipse中免Cygwin的NDK(JNI)配置及Demo调试
- linux 两次 connect()
- 陈怡暖:今将开启为期两天美联储决议会议
- Html5 Viewport学习
- imx6sx-sdb.dtb imx6sx-sdb.dts 设备树 (d:\swwork\solo\linux-3.14.28\arch\arm\boot\dts)
- Appium基于安卓的各种FindElement的控件定位方法实践和建议
- Android性能调优
- java二叉树的遍历算法
- app 性能测试--弱网
- wxPython写计算器