对于想了解套接字–在客户端使用INADDR_ANY的读者,本文将提供新的信息,我们将详细介绍套接字connect,并且为您提供关于'structin6_addr'与-ansi没有名为's6_addr3
对于想了解套接字 – 在客户端使用INADDR_ANY的读者,本文将提供新的信息,我们将详细介绍套接字connect,并且为您提供关于'struct in6_addr'与-ansi没有名为's6_addr32'的成员、BindException:地址已在客户端套接字上使用吗?、c – 套接字编程中的客户端到客户端消息传递、INADDR_ANY 与 INADDR_LOOPBACK的有价值信息。
本文目录一览:- 套接字 – 在客户端使用INADDR_ANY(套接字connect)
- 'struct in6_addr'与-ansi没有名为's6_addr32'的成员
- BindException:地址已在客户端套接字上使用吗?
- c – 套接字编程中的客户端到客户端消息传递
- INADDR_ANY 与 INADDR_LOOPBACK
套接字 – 在客户端使用INADDR_ANY(套接字connect)
// Create client socket if( (sd = socket(PF_INET,SOCK_STREAM,0)) < 0 ) { perror("socket error"); return -1; } bzero(&addr,sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT_NO); addr.sin_addr.s_addr = htonl(INADDR_ANY); // Connect to server socket if(connect(sd,(struct sockaddr *)&addr,sizeof addr) < 0) { perror("Connect error"); return -1; }
具体来说,我是在线:
addr.sin_addr.s_addr = htonl(INADDR_ANY);
在服务器端,我知道INADDR_ANY会将端口绑定到所有可用的接口,但我不确定这在客户端是否有意义.最后,客户端需要在特定接口上进行连接.以前我总是指定IP地址或使用INADDR_LOOPBACK.
The Linux IP man page没有谈到在客户端使用INADDR_ANY.我确实找到了another Stack Overflow post here,它说OP应该在客户端使用INADDR_ANY,但没有给出任何理由或解释.
那实际上是做什么的呢?它是否尝试所有接口,直到找到端口可用于连接的接口?这发生了什么顺序?
谢谢你的回答!
解决方法
INADDR_ANY可以在客户端和服务器上合理地与bind一起使用.与connect()一起使用是没有意义的,应该导致连接失败.
'struct in6_addr'与-ansi没有名为's6_addr32'的成员
在使用no-asm -ansi构buildOpenSSL时,我正在解决一些编译错误。 我正在捕捉错误:
$ ./config no-asm -ansi ... $ make ... gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSLDIR=""/usr/local/ssl"" -DENGInesDIR=""/usr/local/lib/engines"" -Wall -O3 -pthread -m64 -DL_ENDIAN -ansi -fPIC -Iinclude -I. -Icrypto/include -MMD -MF crypto/bio/bss_dgram.d.tmp -MT crypto/bio/bss_dgram.o -c -o crypto/bio/bss_dgram.o crypto/bio/bss_dgram.c In file included from /usr/include/netdb.h:27:0,from ./e_os.h:443,from crypto/bio/bio_lcl.h:2,from crypto/bio/bss_dgram.c:62: crypto/bio/bss_dgram.c: In function ''dgram_get_mtu_overhead'': crypto/bio/bss_dgram.c:433:20: error: ''const struct in6_addr'' has no member named ''s6_addr32'' && IN6_IS_ADDR_V4MAPPED(&tmp_addr)) ^
我在/usr/include/linux/in6.hfind了这个结构体:
#if __UAPI_DEF_IN6_ADDR struct in6_addr { union { __u8 u6_addr8[16]; #if __UAPI_DEF_IN6_ADDR_ALT __be16 u6_addr16[8]; __be32 u6_addr32[4]; #endif } in6_u; #define s6_addr in6_u.u6_addr8 #if __UAPI_DEF_IN6_ADDR_ALT #define s6_addr16 in6_u.u6_addr16 #define s6_addr32 in6_u.u6_addr32 #endif }; #endif /* __UAPI_DEF_IN6_ADDR */
我不记得以前需要定义__UAPI_DEF_IN6_ADDR_ALT 。 search它显示从内核的libc-compat.h 95行左右(如果我parsing正确):
#define __UAPI_DEF_IN6_ADDR 1 /* We unconditionally define the in6_addr macros and glibc must coordinate. */ #define __UAPI_DEF_IN6_ADDR_ALT 1 #define __UAPI_DEF_SOCKADDR_IN6 1 #define __UAPI_DEF_IPV6_MREQ 1 #define __UAPI_DEF_IPPROTO_V6 1 #define __UAPI_DEF_IPV6_OPTIONS 1 #define __UAPI_DEF_IN6_PKTINFO 1 #define __UAPI_DEF_IP6_MTUINFO 1
我应该如何着手定义替代符号?
用C在Windows上清除命令提示符
ansi-terminal:在Windows上意外的行为
Windows控制台是否支持ANSI?
带有ANSI代码的文本编辑器/查看器,支持Windows
让Ansicon在Console2上工作(Windows 7,64位)
系统是Ubuntu 14.04(x86_64):
$ lsb_release -a No LSB modules are available. distributor ID: Ubuntu Description: Ubuntu 14.04.4 LTS Release: 14.04 Codename: trusty
GCC是:
$ gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4 copyright (C) 2013 Free Software Foundation,Inc.
如何在Ruby中为string制作颜色
如何获得Windows PowerShell的ANSI颜色输出?
当使用get-content回显屏幕时,如何启用powershell来解释ansi颜色代码?
Python,Windows,Ansi – 编码,再次
batch file中的ANSI / Unicode冲突
这原来是有趣的…它的缺点是我需要添加-ansi和-D_DEFAULT_SOURCE=1 。 但是, -D_DEFAULT_SOURCE=1种撤消了-ansi正在尝试完成的事情,所以需要包含它。
首先,/ /usr/include/linux/in6.h是错误的头文件。 我发现它通过一个grep的struct in6_addr ,而不是跟踪包括像需要做的事情。
下一个… -D_DEFAULT_SOURCE=1间接来自/usr/include/netinet/in.h :
#ifndef __USE_KERNEL_IPV6_DEFS /* IPv6 address */ struct in6_addr { union { uint8_t __u6_addr8[16]; #ifdef __USE_MISC uint16_t __u6_addr16[8]; uint32_t __u6_addr32[4]; #endif } __in6_u; #define s6_addr __in6_u.__u6_addr8 #ifdef __USE_MISC # define s6_addr16 __in6_u.__u6_addr16 # define s6_addr32 __in6_u.__u6_addr32 #endif }; #endif /* !__USE_KERNEL_IPV6_DEFS */
手动启用__USE_MISC不起作用。 在/usr/include/features.h跟踪__USE_MISC的内容:
/* ... __USE_MISC Define things from 4.3BSD or System V Unix. ... */ #undef __USE_MISC ... #if defined _DEFAULT_SOURCE # define __USE_MISC 1 #endif
最后,从/usr/include/features.h的注释:
_DEFAULT_SOURCE The default set of features (taking precedence over __STRICT_ANSI__).
虽然_DEFAULT_SOURCE=1与-ansi ,但是影响可以限制为受IN6_IS_ADDR_V4MAPPED影响的一个源文件。 也就是说,在C源文件crypto/bio/bss_dgram.c :
/* OpenSSL copyright ... */ #ifndef _DEFAULT_SOURCE # define _DEFAULT_SOURCE 1 #endif #include <stdio.h> #include <errno.h> #include <netinet/in.h> ...
摆弄__USE_KERNEL_IPV6_DEFS让事情变得更糟。 我相信它启用了/usr/include/linux/in6.h ,它与<netinet/in.h>有类似(但完全不同)的成员名称。
总结
以上是小编为你收集整理的''struct in6_addr''与-ansi没有名为''s6_addr32''的成员全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
BindException:地址已在客户端套接字上使用吗?
我有一个客户端-服务器分层的体系结构,客户端向服务器发出类似RPC的请求。我正在使用Tomcat托管servlet,并使用Apache
HttpClient对其进行请求。
我的代码是这样的:
private static final HttpConnectionManager CONN_MGR = new MultiThreadedHttpConnectionManager();
final GetMethod get = new GetMethod();
final HttpClient httpClient = new HttpClient(CONN_MGR);
get.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
get.getParams().setParameter(HttpMethodParams.USER_AGENT,USER_AGENT);
get.setQueryString(encodedParams);
int responseCode;
try {
responseCode = httpClient.executeMethod(get);
} catch (final IOException e) {
...
}
if (responseCode != 200)
throw new Exception(...);
String responseHTML;
try {
responseHTML = get.getResponseBodyAsString(100*1024*1024);
} catch (final IOException e) {
...
}
return responseHTML;
它在负载较轻的环境中效果很好,但是当我每秒发出数百个请求时,我开始看到这种情况-
Caused by: java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:336)
at java.net.Socket.bind(Socket.java:588)
at java.net.Socket.<init>(Socket.java:387)
at java.net.Socket.<init>(Socket.java:263)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
有关如何解决此问题的任何想法?我猜想这与客户端尝试重用临时客户端端口有关,但是为什么会这样/我该如何解决?谢谢!
c – 套接字编程中的客户端到客户端消息传递
现在我需要知道如何完成客户端到客户端的消息传递部分以及如何完成工作.我只知道,例如,如果客户端A和客户端B需要相互通信,客户端A必须将消息发送到服务器,服务器接收消息并将其发送给客户端B.
如果这是正确的方法,请帮助我知道服务器应该如何知道接收器的任何内容(在这种情况下是客户端B)?
如果我没有清楚地解释我的问题,请告诉我.
任何帮助表示赞赏.
解决方法
1-客户A:-hey,Server!.告诉客户B创建一个comm服务器,这样我就可以直接与他通信.
2-服务器:-hey,客户B!启动服务器实例并告诉我连接属性,以便我可以将其转发给客户端A,以便他可以连接到您.
3-客户B:-hey,Server!.我已准备好接受客户端A的连接请求.这是我的连接属性…
4-服务器:-Client A !!这里是客户端B的连接属性.接受或离开它…我已经完成了..
5-客户端A:-hey,服务器B!..我可以连接吗?..
这就是协议..因此任何客户端首先向服务器发起一个请求,其中包含消息类型“我,请求连接到客户端x ..”.服务器命令客户端x,客户端x响应,服务器中继对发起者客户端的响应……此外,您应该实现错误处理,拒绝策略或您可以想到的一些其他事情来管理整个协议.
INADDR_ANY 与 INADDR_LOOPBACK
INADDR_ANY是ANY,是绑定地址0.0.0.0上的监听, 能收到任意一块网卡的连接;
INADDR_LOOPBACK, 也就是绑定地址LOOPBAC, 往往是127.0.0.1, 只能收到127.0.0.1上面的连接请求
今天关于套接字 – 在客户端使用INADDR_ANY和套接字connect的分享就到这里,希望大家有所收获,若想了解更多关于'struct in6_addr'与-ansi没有名为's6_addr32'的成员、BindException:地址已在客户端套接字上使用吗?、c – 套接字编程中的客户端到客户端消息传递、INADDR_ANY 与 INADDR_LOOPBACK等相关知识,可以在本站进行查询。
本文标签: