同步锦浪云模块
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
package org.dromara.synjinlangyun;
|
||||
|
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
|
||||
/**
|
||||
* 同步锦浪云模块
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@EnableDubbo
|
||||
@SpringBootApplication
|
||||
public class RuoYiSynjinlangyunApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(RuoYiSynjinlangyunApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ 同步锦浪云模块启动成功 ლ(´ڡ`ლ)゙ ");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package org.dromara.synjinlangyun.client;
|
||||
|
||||
import org.dromara.synjinlangyun.listener.J60870ClientListener;
|
||||
import org.openmuc.j60870.ClientConnectionBuilder;
|
||||
import org.openmuc.j60870.Connection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class J60870Client implements Runnable {
|
||||
|
||||
//监听类
|
||||
private J60870ClientListener listener;
|
||||
//连接类
|
||||
private Connection connection;
|
||||
//连接参数
|
||||
private ClientConnectionBuilder clientConnectionBuilder;
|
||||
|
||||
|
||||
public J60870Client() throws IOException{
|
||||
try {
|
||||
//获取server对象,从站的IP地址对象
|
||||
InetAddress address = InetAddress.getByName("127.0.0.1");
|
||||
|
||||
//创建连接参数对象
|
||||
clientConnectionBuilder = new ClientConnectionBuilder(address);
|
||||
//设置socket的连接超时时间
|
||||
clientConnectionBuilder.setConnectionTimeout(60000);
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//主站与从站连接
|
||||
connection = clientConnectionBuilder.build();
|
||||
|
||||
//配置数据回调类
|
||||
listener = new J60870ClientListener();
|
||||
connection.startDataTransfer(listener);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//关闭连接
|
||||
public void disconnect(){
|
||||
try {
|
||||
this.connection.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package org.dromara.synjinlangyun.listener;
|
||||
|
||||
import org.openmuc.j60870.ASdu;
|
||||
import org.openmuc.j60870.ConnectionEventListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class J60870ClientListener implements ConnectionEventListener {
|
||||
|
||||
//监听从站发来的数据
|
||||
@Override
|
||||
public void newASdu(ASdu aSdu) {
|
||||
System.out.println(aSdu.toString());
|
||||
}
|
||||
|
||||
//监听连接关闭
|
||||
@Override
|
||||
public void connectionClosed(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user