ubuntu connect 是 errno 为111 115 101 22 错误分析

22:参数错误,比如ip地址不合法,没有目标端口等

101:网络不可达,比如不能ping通

111:链接被拒绝,比如目标关闭链接等

115:当链接设置为非阻塞时,目标没有及时应答,返回此错误,socket可以继续使用

 

附录:Linux的错误码表(errno table)

_ 124 EMEDIUMTYPE_ Wrong medium type
_ 123 ENOMEDIUM__ No medium found
_ 122 EDQUOT___  Disk quota exceeded
_ 121 EREMOTEIO__ Remote I/O error
_ 120 EISNAM___  Is a named type file
_ 119 ENAVAIL___ No XENIX semaphores available
_ 118 ENOTNAM___ Not a XENIX named type file
_ 117 EUCLEAN___ Structure needs cleaning
_ 116 ESTALE___  Stale NFS file handle
_ 115 EINPROGRESS  +Operation now in progress
_ 114 EALREADY__  Operation already in progress
_ 113 EHOSTUNREACH  No route to host
_ 112 EHOSTDOWN__ Host is down
_ 111 ECONNREFUSED  Connection refused
_ 110 ETIMEDOUT_  +Connection timed out
_ 109 ETOOMANYREFS  Too many references: cannot splice
_ 108 ESHUTDOWN__ Cannot send after transport endpoint shutdown
_ 107 ENOTCONN__  Transport endpoint is not connected
_ 106 EISCONN___ Transport endpoint is already connected
_ 105 ENOBUFS___ No buffer space available
_ 104 ECONNRESET_  Connection reset by peer
_ 103 ECONNABORTED  Software caused connection abort
_ 102 ENETRESET__ Network dropped connection on reset
_ 101 ENETUNREACH_ Network is unreachable
_ 100 ENETDOWN__  Network is down
_  99 EADDRNOTAVAIL Cannot assign requested address
_  98 EADDRINUSE_  Address already in use
_  97 EAFNOSUPPORT  Address family not supported by protocol
_  96 EPFNOSUPPORT  Protocol family not supported
_  95 EOPNOTSUPP_  Operation not supported
_  94 ESOCKTNOSUPPORT Socket type not supported
_  93 EPROTONOSUPPORT Protocol not supported
_  92 ENOPROTOOPT_ Protocol not available
_  91 EPROTOTYPE_  Protocol wrong type for socket
_  90 EMSGSIZE__ +Message too long
_  89 EDESTADDRREQ  Destination address required
_  88 ENOTSOCK__  Socket operation on non-socket
_  87 EUSERS___  Too many users
_  86 ESTRPIPE__  Streams pipe error
_  85 ERESTART__  Interrupted system call should be restarted
_  84 EILSEQ___  Invalid or incomplete multibyte or wide character
_  83 ELIBEXEC__  Cannot exec a shared library directly
_  82 ELIBMAX___ Attempting to link in too many shared libraries
_  81 ELIBSCN___ .lib section in a.out corrupted
_  80 ELIBBAD___ Accessing a corrupted shared library
_  79 ELIBACC___ Can not access a needed shared library
_  78 EREMCHG___ Remote address changed
_  77 EBADFD___  File descriptor in bad state
_  76 ENOTUNIQ__  Name not unique on network
_  75 EOVERFLOW__ Value too large for defined data type
_  74 EBADMSG__  +Bad message
_  73 EDOTDOT___ RFS specific error
_  72 EMULTIHOP__ Multihop attempted
_  71 EPROTO___  Protocol error
_  70 ECOMM____ Communication error on send
_  69 ESRMNT___  Srmount error
_  68 EADV____  Advertise error
_  67 ENOLINK___ Link has been severed
_  66 EREMOTE___ Object is remote
_  65 ENOPKG___  Package not installed
_  64 ENONET___  Machine is not on the network
_  63 ENOSR____ Out of streams resources
_  62 ETIME____ Timer expired
_  61 ENODATA___ No data available
_  60 ENOSTR___  Device not a stream
_  59 EBFONT___  Bad font file format
_  57 EBADSLT___ Invalid slot
_  56 EBADRQC___ Invalid request code
_  55 ENOANO___  No anode
_  54 EXFULL___  Exchange full
_  53 EBADR____ Invalid request descriptor
_  52 EBADE____ Invalid exchange
_  51 EL2HLT___  Level 2 halted
_  50 ENOCSI___  No CSI structure available
_  49 EUNATCH___ Protocol driver not attached
_  48 ELNRNG___  Link number out of range
_  47 EL3RST___  Level 3 reset
_  46 EL3HLT___  Level 3 halted
_  45 EL2NSYNC__  Level 2 not synchronized
_  44 ECHRNG___  Channel number out of range
_  43 EIDRM____ Identifier removed
_  42 ENOMSG___  No message of desired type
_  40 ELOOP____ Too many levels of symbolic links
_  39 ENOTEMPTY_  +Directory not empty
_  38 ENOSYS___ +Function not implemented
_  37 ENOLCK___ +No locks available
_  36 ENAMETOOLONG +File name too long
_  35 EDEADLK__  +Resource deadlock avoided
_  34 ERANGE___ +Numerical result out of range
_  33 EDOM____ +Numerical argument out of domain
_  32 EPIPE___  +Broken pipe
_  31 EMLINK___ +Too many links
_  30 EROFS___  +Read-only file system
_  29 ESPIPE___ +Illegal seek
_  28 ENOSPC___ +No space left on device
_  27 EFBIG___  +File too large
_  26 ETXTBSY___ Text file busy
_  25 ENOTTY___ +Inappropriate ioctl for device
_  24 EMFILE___ +Too many open files
_  23 ENFILE___ +Too many open files in system
_  22 EINVAL___ +Invalid argument
_  21 EISDIR___ +Is a directory
_  20 ENOTDIR__  +Not a directory
_  19 ENODEV___ +No such device
_  18 EXDEV___  +Invalid cross-device link
_  17 EEXIST___ +File exists
_  16 EBUSY___  +Device or resource busy
_  15 ENOTBLK___ Block device required
_  14 EFAULT___ +Bad address
_  13 EACCES___ +Permission denied
_  12 ENOMEM___ +Cannot allocate memory
_  11 EAGAIN___ +Resource temporarily unavailable
_  10 ECHILD___ +No child processes
__ 9 EBADF___  +Bad file descriptor
__ 8 ENOEXEC__  +Exec format error
__ 7 E2BIG___  +Argument list too long
__ 6 ENXIO___  +No such device or address
__ 5 EIO____  +Input/output error
__ 4 EINTR___  +Interrupted system call
__ 3 ESRCH___  +No such process
__ 2 ENOENT___ +No such file or directory
__ 1 EPERM___  +Operation not permitted
#_  0 --_____  Success

为了在Ubuntu上使用C语言进行MQTT通讯,您需要进行以下步骤: 1. 安装MQTT库:您可以使用Paho MQTT C库进行MQTT通讯。使用以下命令可以安装此库: ``` sudo apt-get install libpaho-mqtt-dev ``` 2. 编写C程序:您可以使用以下样本程序进行MQTT通讯: ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <errno.h> #include <mqtt.h> #define SERVER_ADDRESS "localhost" #define CLIENT_ID "testclient" #define TOPIC "testtopic" #define QOS 1 #define TIMEOUT 10000L volatile int toStop = 0; void usage(void) { printf("Usage: testpub [-h <broker_host>] [-p <broker_port>]\n"); exit(EXIT_FAILURE); } void cfinish(int sig) { signal(SIGINT, NULL); toStop = 1; } int main(int argc, char* argv[]) { char* url = SERVER_ADDRESS; int port = 1883; int rc = 0; char* clientid = CLIENT_ID; char* topic = TOPIC; int qos = QOS; long timeout = TIMEOUT; MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; MQTTClient client; MQTTClient_message pubmsg = MQTTClient_message_initializer; MQTTClient_deliveryToken token; int ch; while ((ch = getopt(argc, argv, "h:p:")) != -1) { switch (ch) { case 'h': url = optarg; break; case 'p': port = atoi(optarg); break; default: usage(); } } MQTTClient_create(&client, url, clientid, MQTTCLIENT_PERSISTENCE_NONE, NULL); signal(SIGINT, cfinish); signal(SIGTERM, cfinish); conn_opts.keepAliveInterval = 20; conn_opts.cleansession = 1; if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS) { printf("Failed to connect, return code %d\n", rc); exit(EXIT_FAILURE); } while (!toStop) { char* payload = "Hello, world"; int payloadlen = strlen(payload); pubmsg.payload = payload; pubmsg.payloadlen = payloadlen; pubmsg.qos = qos; pubmsg.retained = 0; MQTTClient_publishMessage(client, topic, &pubmsg, &token); rc = MQTTClient_waitForCompletion(client, token, timeout); printf("Message with delivery token %d delivered\n", token); sleep(1); } MQTTClient_disconnect(client, 10000); MQTTClient_destroy(&client); return rc; } ``` 3. 编译程序:使用以下命令可以编译程序: ``` gcc -o testpub testpub.c -lpaho-mqtt3c ``` 4. 运行程序:使用以下命令可以运行程序: ``` ./testpub ``` 5. 测试:打开MQTT客户端,订阅“testtopic”主题,您应该会收到程序发布的消息“Hello, world”。 以上是在Ubuntu上使用C语言进行MQTT通讯的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值