iNet

Java NIO 套接字【源码笔记】

别说谁变了你拦得住时间么 提交于 2020-02-26 13:15:21
目录 一、TCP/IP套接字函数交互图示 二、交互示例 三、本地函数释义 四、本文总结 五、参考书籍 六、系列文章 一、TCP/IP套接字函数交互图示 二、交互示例 本文以代码示例跟踪调用Native函数,看下原型函数的具体释义。例子中“客户端”从文件test02.tmp读取内容后,通过socket发送到“服务端”后写入test01.tmp文件中。 服务端示例 ServerSocketChannel ssc = ServerSocketChannel.open(); // @1 ssc.socket().bind (new InetSocketAddress(8121)); // @2 ssc.configureBlocking (false); // @3 while (true) { SocketChannel sc = ssc.accept( ); // @4 if (sc == null) { Thread.sleep (2000); } else { Path path = Paths.get("/mytest/test01.tmp"); FileChannel fileChannel = FileChannel.open(path, EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE

linux入门系列11--Centos7网络服务管理

元气小坏坏 提交于 2020-02-26 02:31:09
通过前面文章的学习已经掌握了Linux系统配置管理的知识,本文讲解Centos7网络配置知识。 Linux要对外提供服务,需要保证网络通信正常,因此需要正确配置网络参数。本文将讲解如何使用Network Manager配置网络参数、管理网络会话服务,以及如何手工绑定mode6模式双网卡,实现网络的负载均衡。 一、Centos7网络概述 1.1 Centos7网络管理 对于网络功能来说,CentOS7与之前的版本变化较大。 在RHEL/CentOS 6及以前的版本中,网络功能是通过一系列网络相关的脚本文件实现(如/etc/init.d/network文件,及如下/sbin/if*文件等)。 从RHEL/CentOS 7开始,网络功能默认由NetworkManager以服务的形式提供。Network Manager是一个能够动态控制和配置网络的守护进程,管理网络服务和网络连接,对应NetworkManager.service服务(其配置文件/etc/NetworkManager/NetworkManager.conf,默认为空,无需任何配置) 虽然RHEL/CentOS 6中的网络相关的脚本文件仍然以network.service的形式被支持,但是建议使用NetworkManager.service来进行配置和管理。 并且只能选择其中一种,不然会有冲突。 1.2 network

从linux源码看socket(tcp)的timeout

徘徊边缘 提交于 2020-01-07 15:58:00
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 从linux源码看socket(tcp)的timeout 前言 网络编程中超时时间是一个重要但又容易被忽略的问题,对其的设置需要仔细斟酌。在经历了数次物理机宕机之后,笔者详细的考察了在网络编程(tcp)中的各种超时设置,于是就有了本篇博文。本文大部分讨论的是socket设置为block的情况,即setNonblock(false),仅在最后提及了nonblock socket(本文基于linux 2.6.32-431内核)。 connectTimeout 在讨论connectTimeout之前,让我们先看下java和C语言对于socket connect调用的函数签名: java: // 函数调用中携带有超时时间 public void connect(SocketAddress endpoint, int timeout) ; C语言: // 函数调用中并不携带超时时间 int connect(int sockfd, const struct sockaddr * sockaddr, socklen_t socklent) 操作系统提供的connect系统调用并没有提供timeout的参数设置而java却有,我们先考察一下原生系统调用的超时策略。 connect系统调用

Linux下的socket编程实践(五)设置套接字I/O超时的方案

▼魔方 西西 提交于 2020-01-07 05:10:47
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> (一)使用alarm 函数设置超时 #include <unistd.h> unsigned int alarm(unsigned int seconds); 它的主要功能是设置信号传送闹钟。信号SIGALRM在经过seconds指定的秒数后传送给目前的进程,如果在定时未完成的时间内再次调用了alarm函数,则后一次定时器设置将覆盖前面的设置,当seconds设置为0时,定时器将被取消。它返回上次定时器剩余时间,如果是第一次设置则返回0。 void sigHandlerForSigAlrm(int signo) { return ; } signal(SIGALRM, sigHandlerForSigAlrm); alarm(5); int ret = read(sockfd, buf, sizeof(buf)); if (ret == -1 && errno == EINTR) { // 阻塞并且达到了5s,超时,设置返回错误码 errno = ETIMEDOUT; } else if (ret >= 0) { // 正常返回(没有超时), 则将闹钟关闭 alarm(0); } 如果read一直处于阻塞状态被SIGALRM信号中断而返回,则表示超时,否则未超时已读取到数据,取消闹钟。但这种方法不常用

OMNET++ How to retain all functions in AODVRouting class but override sendAODVPacket function only?

蹲街弑〆低调 提交于 2020-01-07 04:13:27
问题 I'm writting a simple module to simulate a misbehaved node that inherits all functions from AODRouting, and overriding sendAODVPacket function by dropping the AODV packet once it has received it. The .h file as follows: #ifndef __PROJECT1_SELFISHBASENODE_H_ #define __PROJECT1_SELFISHBASENODE_H_ #include <omnetpp.h> #include "AODVRouting.h" using namespace inet; class SelfishBaseNode : public AODVRouting { protected: virtual void initialize(); virtual void sendAODVPacket(AODVControlPacket

Debian10下配置网络

南楼画角 提交于 2020-01-06 23:31:34
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Debian10 configure network: edit network configure file: /etc/network/interfaces #configure static IP: source /etc/network/interfaces.d/* #Loopback address auto lo iface lo inet loopback # set network ens33 to static IP # auto connect network auto ens33 # static stand for use static ip, dhcp for dynamical ip iface ens33 inet static # set ip address address 192.168.1.188 #set subnetwork mask netmask 255.255.255.0 # set gateway gateway 192.168.1.1 #configure dynamical IP: source /etc/network/interfaces.d/* #Loopback address auto lo iface lo inet loopback # set

网站添加ipv6访问

一笑奈何 提交于 2020-01-06 15:27:00
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 转载请注明文章出处: https://tlanyan.me/add-ipv6-for-website 今天折腾境外vps的时候忽然想到5刀每个月的服务器都有ipv6,为何国内服务器默认就不给ipv6呢?现在都2020年了,网站该支持ipv6访问了吧?!!于是查阅各方文档,终于给网站添加了ipv6,目前本站已支持ipv6访问。 本文简要介绍给网站添加ipv6的配置过程。 配置流程 1. 首先服务器要有ipv6地址。如果是海外vps,大部分情况下都有(或者可在网页控制台直接添加)。国内的情形比较特殊,例如本人用的阿里云就需要 申请ipv6内测资格 等一系列复杂操作才能用上ipv6。阿里云服务器添加ipv6的教程请参考: https://help.aliyun.com/document_detail/100901.html?spm=a2c4g.11186623.6.907.207779323rt1Ly 。 有ipv6公网地址后,Linux系统在终端输入 ip addr , 会有类似输出: inet6 240b:4001:1:400:e72d:dab:c902:b662/64 scope global valid_lft forever preferred_lft forever inet6 fe80::216

OMNeT++ issue with linking INET

淺唱寂寞╮ 提交于 2020-01-06 07:28:54
问题 During the build of my new OMNeT++ project I have encountered following error: out/clang-debug//myUdp.o:(.rdata[_ZTI5myUdp]+0x10): undefined reference to 'typeinfo for inet::ApplicationBase' I have already configured INET reference (Project "myUdp" -> Properties -> Project reference -> inet checkbox selected) This is INET Makemake configuration: Target tab and Compile tab This is Makemake configuration of my project (myUdp): Compile tab and Link tab And the C++ code: MyUdp.cc #include <inet

How to use ManetRouter.ned with veins

扶醉桌前 提交于 2020-01-03 05:56:01
问题 I want to use ManetRouter.ned(https://github.com/inet-framework/inet/blob/master/src/inet/node/inet/ManetRouter.ned) in veins. How can i use it? I mean is there a way to use inet 4.0.0 files in veins as veins is compatable with inet 3.6.4 only? Please help. 回答1: Veins master @bfdfc10 is compatible with INET 4.0.0. Note, however, that linking against INET 4.0.0 on Windows appears to be impossible. Issue #379 of the INET framework is tracking this bug. You might have to wait for the next INET

How to use ManetRouter.ned with veins

对着背影说爱祢 提交于 2020-01-03 05:55:05
问题 I want to use ManetRouter.ned(https://github.com/inet-framework/inet/blob/master/src/inet/node/inet/ManetRouter.ned) in veins. How can i use it? I mean is there a way to use inet 4.0.0 files in veins as veins is compatable with inet 3.6.4 only? Please help. 回答1: Veins master @bfdfc10 is compatible with INET 4.0.0. Note, however, that linking against INET 4.0.0 on Windows appears to be impossible. Issue #379 of the INET framework is tracking this bug. You might have to wait for the next INET