赞
踩
连接时出现异常,具体如下:
- connect to server xxx(服务器对应公网IP):22122 fail
- java.net.SocketTimeoutException: connect timed out
- at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
- at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
- at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
- at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
- at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
- at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
- at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
- at java.net.Socket.connect(Socket.java:589)
- at org.csource.fastdfs.TrackerGroup.getConnection(TrackerGroup.java:46)
- at org.csource.fastdfs.TrackerGroup.getConnection(TrackerGroup.java:68)
- at org.csource.fastdfs.TrackerClient.getConnection(TrackerClient.java:57)
- at top.javahai.subtlechat.api.Tests.testUpload(Tests.java:67)
- at top.javahai.subtlechat.api.Tests.main(Tests.java:23)
这里有几个注意事项需要大致说下,由于我这边都是本地使用进行远程连接的,所以在部署安装fastdsf相关应用时,对应的IP需更改成对应的公网IP或域名。其次是相关端口需添加到阿里服务器的安全组规则内,如下所示:
接下来是关于解决问题的大致思路有以下几个:
关闭防火墙重新连接即可,连接成功后上传完成会返回上传文件路径。由于我是本地测试类调用,具体代码见下:
- public static void testUpload() {
- try {
- //初始化配置文件
- ClientGlobal.initByProperties("fastdfs-client.properties");
- //实例化TrackerClient对象
- TrackerClient tracker = new TrackerClient();
- //获取连接对象
- TrackerServer trackerServer = tracker.getConnection();
- //重置StorageServer对象
- StorageServer storageServer = null;
- //获取客户端连接
- StorageClient1 client = new StorageClient1(trackerServer, storageServer);
- NameValuePair nvp[] = null;
- //上传到文件系统并返回对应路径
- String fileId = client.upload_file1("M:\\image\\002.png", "png",
- nvp);
- System.out.println("上传返回消息:"+fileId);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
对应配置文件如下:
- fastdfs.connect_timeout_in_seconds = 5
- fastdfs.network_timeout_in_seconds = 30
- fastdfs.charset = UTF-8
- fastdfs.http_anti_steal_token = false
- #服务器密钥,默认为“FastDFS1234567890”。可更改但必须保证服务端与客户端一致
- fastdfs.http_secret_key = FastDFS1234567890
- fastdfs.http_tracker_http_port = 80
- #服务器公网IP与端口
- fastdfs.tracker_servers = xxxx:22122
- fastdfs.connection_pool.enabled = true
- fastdfs.connection_pool.max_count_per_entry = 500
- fastdfs.connection_pool.max_idle_time = 3600
- fastdfs.connection_pool.max_wait_time_in_ms = 1000
连接上传成功效果如下:
- Disconnected from the target VM, address: '127.0.0.1:51744', transport: 'socket'
- 上传返回消息:group1/M00/00/00/L2PKeWDztcuAPdf8AAIohYtxWLY743.png
这边有个小插曲,就是关于防火墙的问题。因为不小心看错命令执行了暂时关闭防火墙声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。