/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package a.proxy.test;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import org.apache.mina.core.RuntimeIoException;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.future.IoFutureListener;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.core.session.IoSession;
public class ClientToProxyIoHandler extends AbstractProxyIoHandler {
private final ServerToProxyIoHandler connectorHandler = new ServerToProxyIoHandler();
private final IoConnector connector;
private final SocketAddress[] remoteAddress;
public ClientToProxyIoHandler(IoConnector connector,
SocketAddress[] remoteAddress) {
this.connector = connector;
this.remoteAddress = remoteAddress;
connector.setHandler(connectorHandler);
}
InetSocketAddress isas[]=new InetSocketAddress[]{
new InetSocketAddress("113.31.18.232", 22),
new InetSocketAddress("113.31.18.233", 22),
new InetSocketAddress("113.31.18.234", 22),
new InetSocketAddress("113.31.18.235", 22),
new InetSocketAddress("113.31.18.236", 22),
};
int k=0;
@Override
public void sessionOpened(final IoSession session) throws Exception {
//isa[(k++)%isa.length]
SocketAddress isa= remoteAddress[(k++)%remoteAddress.length];
System.out.println("#$#$"+isa);
connector.connect(isa).addListener(new IoFutureListener<ConnectFuture>() {
public void operationComplete(ConnectFuture future) {
try {
future.getSession().setAttribute(OTHER_IO_SESSION, session);
session.setAttribute(OTHER_IO_SESSION, future.getSession());
IoSession session2 = future.getSession();
session2.resumeRead();
session2.resumeWrite();
} catch (RuntimeIoException e) {
// Connect failed
session.close(true);
} finally {
session.resumeRead();
session.resumeWrite();
}
}
});
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package a.proxy.test;
import java.nio.charset.Charset;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
public abstract class AbstractProxyIoHandler extends IoHandlerAdapter {
private static final Charset CHARSET = Charset.forName("iso8859-1");
public static final String OTHER_IO_SESSION = AbstractProxyIoHandler.class.getName()+".OtherIoSession";
@Override
public void sessionCreated(IoSession session) throws Exception {
session.suspendRead();
session.suspendWrite();
}
@Override
public void sessionClosed(IoSession session) throws Exception {
if (session.getAttribute( OTHER_IO_SESSION ) != null) {
IoSession sess = (IoSession) session.getAttribute(OTHER_IO_SESSION);
sess.setAttribute(OTHER_IO_SESSION, null);
sess.close(false);
session.setAttribute(OTHER_IO_SESSION, null);
}
}
@Override
public void messageReceived(IoSession session, Object message)
throws Exception {
IoBuffer rb = (IoBuffer) message;
IoBuffer wb = IoBuffer.allocate(rb.remaining());
rb.mark();
wb.put(rb);
wb.flip();
((IoSession) session.getAttribute(OTHER_IO_SESSION)).write(wb);
rb.reset();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package a.proxy.test;
import java.net.InetSocketAddress;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
public class Main {
public static void main(String[] args2) throws Exception {
// Create TCP/IP acceptor.
NioSocketAcceptor acceptor = new NioSocketAcceptor();
IoConnector connector = new NioSocketConnector();
connector.setConnectTimeoutMillis(30*1000L);
ClientToProxyIoHandler handler = new ClientToProxyIoHandler(connector, new InetSocketAddress[]{ new InetSocketAddress("127.0.0.1", 80)});
acceptor.setHandler(handler);
acceptor.bind(new InetSocketAddress(777));
System.out.println("Listening on port " + 777);
}
}
分享到:
相关推荐
服务代理层实现了服务接口的透明代理,生成服务的客户端 Stub 和服务器端 Skeleton。ServiceProxy 是这个层次的核心,它负责将方法调用转换为远程调用。ProxyFactory 接口允许用户自定义服务代理实现,以满足特定...
他还精通Linux操作系统,特别是使用Nginx作为反向代理服务器以及CDN和Varnish进行静态内容缓存,这对于提升网站性能和响应速度至关重要。 在数据库管理上,吴华不仅熟悉Oracle、MySQL等关系型数据库,还了解Redis、...
- **Collections.sort**:对于`List`的排序,`Collections.sort()` 方法内部实际上是基于归并排序的一个变种——TimSort。这种排序算法首先会检查列表是否已经部分有序,如果是,则直接利用这种有序性进行排序,这...
计算机发展与计算机应用概述.pdf
计算机二级公共基础知识全集合.pdf
计算机机试答案.pdf
内容概要:本文详细介绍了基于STM32F103RCT6的750W全桥逆变器设计方案,涵盖硬件电路设计、软件编程以及保护机制等方面。硬件部分包括主控芯片的选择、PWM配置、Boost升压电路、PCB布局优化等;软件部分涉及并离网切换的状态机设计、过流保护、风扇控制算法、并机功能实现等。文中还分享了许多实战经验和调试技巧,如死区时间配置、电流采样方法、并网同步算法等。 适合人群:具有一定电子电路和嵌入式开发基础的技术人员,尤其是从事逆变器及相关电力电子产品开发的工程师。 使用场景及目标:适用于希望深入了解逆变器工作原理和技术实现的开发者,特别是那些需要掌握并离网切换、高效电源管理及可靠保护机制的人群。目标是帮助读者构建一个稳定可靠的逆变器系统,能够应对各种复杂的工作环境。 其他说明:本文不仅提供了详细的理论讲解,还有丰富的代码片段和实践经验分享,有助于读者更好地理解和应用相关技术。
内容概要:本文详细介绍了如何利用Simulink在MATLAB环境中搭建单相全桥逆变器的仿真模型。首先,通过构建H桥结构,连接直流电源和RL负载,并引入PWM控制器进行开关管的控制。接着,针对仿真过程中遇到的各种问题,如谐波失真、开关管直通等问题,提出了具体的解决方案,包括加入LC滤波器、设置死区时间和优化PWM参数等。此外,还探讨了通过MATLAB脚本自动化测试不同参数组合的方法,以及如何提高电压利用率和降低谐波失真。最终,通过对仿真结果的分析,验证了所提方法的有效性和优越性。 适合人群:电力电子工程师、科研人员、高校学生等对逆变器仿真感兴趣的群体。 使用场景及目标:适用于研究和开发高效、稳定的逆变器系统,旨在通过仿真手段减少实验成本,优化设计方案,提高系统的性能指标。 其他说明:文中提供了详细的建模步骤和技术细节,帮助读者更好地理解和掌握相关技术和方法。同时,强调了仿真参数的选择和优化对于获得理想仿真结果的重要性。
计算机红外通信.pdf
软考考试学习必备资料.md
基于cornerstonejs开发移动端
构建交互式图片画廊
源码
Bosch Rexroth IndraWorks Ds IndraWorks Ds 14V16.310.0
java面向对象 - 类与对象
内容概要:本文详细介绍了基于AT32平台的无感FOC(Field-Oriented Control)控制算法,特别是针对永磁同步电机(PMSM)和无刷直流电机(BLDC)的位置速度观测器实现。文章首先展示了启动策略的独特之处,即跳过传统前馈强拖阶段,直接利用矢量控制环和观测器协同启动。接着深入探讨了磁链观测器的核心算法,包括磁链积分、反正切求角度以及速度估算部分使用的改良版PLL。此外,文中还提到了容差配置模块,用于提高系统的鲁棒性和稳定性。最后,强调了模块间良好的解耦设计,使得各功能模块拥有明确的输入输出接口,增强了代码的可维护性和移植性。 适合人群:从事电机控制系统开发的技术人员,尤其是对无感FOC算法感兴趣的工程师。 使用场景及目标:适用于需要高精度、快速响应的电机控制系统开发项目,旨在提升系统的鲁棒性和稳定性,特别是在电机参数存在偏差的情况下依然能够保持良好性能。 其他说明:文章不仅提供了详细的代码实现,还分享了许多实用的经验和技术细节,如启动策略、磁链观测器的物理本质、速度估算方法等,有助于读者更好地理解和应用无感FOC算法。
计算机机房de设置与维护.pdf
《Java 面试进阶指北 》 质量很高,专为面试打造
内容概要:本文详细介绍了外转子开关磁阻电机(ER-SRM)的多目标优化方法,主要采用NSGA-II算法进行优化。文章首先解释了为什么ER-SRM比传统内转子电机更难以优化,接着展示了如何利用NSGA-II算法解决这一难题。文中提供了详细的Matlab代码,包括种群初始化、交叉变异操作、非支配排序以及目标函数的定义。此外,还讨论了优化过程中的一些注意事项,如初始种群多样性的保持、交叉变异参数的选择、目标函数的设计等。最后,通过具体的案例和图表展示了优化结果及其应用价值。 适合人群:从事电机设计与优化的研究人员和技术人员,尤其是对外转子开关磁阻电机感兴趣的读者。 使用场景及目标:适用于需要同时优化电机效率、转矩波动和制造成本等多种目标的情况。通过NSGA-II算法,可以在多个相互冲突的目标间找到最佳平衡点,从而提高电机的整体性能。 其他说明:文章不仅提供了完整的Matlab代码实现,还分享了许多实践经验,如参数设置的经验公式、常见错误及解决方案等。这对于理解和掌握NSGA-II算法的实际应用非常有帮助。
慢行智远V2.0"是一款专业的串口数据采集与信号分析软件,集成了多通道数据采集、实时波形显示、FFT频谱分析、FIR滤波处理等高级功能。软件提供直观的用户界面,支持亮色/暗色两种主题,具备强大的数据处理与可视化能力。核心功能包括: 全面的串口通信支持(多种波特率、数据位、停止位、校验位配置) 多通道(最多4通道)波形实时显示与分析 高级信号处理(FFT频谱分析、FIR滤波、信号平滑等) 智能数据管理(断行数据处理、大数据量优化) 数据记录与导出(文本、CSV、图像多种格式) 自适应界面设计(支持高DPI显示、暗色主题) 适用人群 嵌入式开发工程师:需要通过串口调试单片机、开发板等嵌入式设备 电子工程师:进行电路测试、信号采集与分析的专业人员 工业自动化技术人员:监测工业设备数据、进行状态分析 科研教育工作者:用于实验数据采集、科学研究与教学演示 医疗设备开发人员:分析生物电信号、开发医疗监测设备 物联网开发者:调试传感器网络、分析传感器数据 硬件测试工程师:进行产品质量检测、性能评估 使用场景及目标 研发调试场景 单片机开发:实时监控传感器数据、调试通信协议、观察系统运行状态等等