FastDFS java 客户端上传文件错误
本帖最后由 wp00000008 于 2010-02-22 18:02 编辑
TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("192.168.100.68", 22122)});
TrackerClient tc = new TrackerClient(tg);
TrackerServer ts = tc.getConnection();
StorageServer ss = tc.getStoreStorage(ts);
StorageClient1 sc1 = new StorageClient1(ts, ss);
fileid = sc1.upload_file1("c:/a.txt", "txt", meta_list); //此行异常
System.out.println("Upload local file "+item+" ok, fileid="+fileid);
以上是代码片段,上传出现java.net.ConnectException: Connection refused: connect异常
服务器tracker和storage正常运行,检查storage日志,无状况。
检查tracker日志,信息如下:
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection reset by peer
[2010-02-22 16:59:56] ERROR - file: tracker_service.c, line: 1593, client ip: , send data fail, errno: 104, error info: Connection r
storage日志如下:
[2010-02-22 16:36:51] INFO - FastDFS v1.25, base_path=/root/chengsj/fastdfs/group0, store_path_count=1, subdir_count_per_path=256, group_name=group1, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=5, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=200ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time: 23:59, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=60s, thread_stack_size=512 KB, upload_priority=10, check_file_duplicate=0, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0
[2010-02-22 16:36:52] INFO - file: storage_param_getter.c, line: 225, storage_ip_changed_auto_adjust=1
[2010-02-22 16:36:52] INFO - file: tracker_client_thread.c, line: 257, successfully connect to tracker server 127.0.0.1:22122, as a tracker client, my ip is 127.0.0.1
服务器:FastDFS_v1.25
客户端:fastdfs_client_v1.12.jar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
多谢帮助,这个问题解决了。
回复 1# wp00000008
定位一下是哪行代码引起的这个错误呢?
看出错信息,应该是连接服务器失败。
fileid = sc1.upload_file1("c:/a.txt", "txt", meta_list); //此行异常
以上代码行出问题
如果是连接服务器失败,那服务器日志里面是不会有
send data fail, errno
之类的信息的
我想问题应该是连接上了,可是在处理上传的时候,出现了问题
回复 3# wp00000008
能否使用如下的形式,将出现异常时的调用堆栈打印出来呢:
try
{
//访问FastDFS的若干行代码
}
catch(Exception ex)
{
ex.printStackTrace();
}
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at org.csource.fastdfs.ClientGlobal.getSocket(ClientGlobal.java:99)
at org.csource.fastdfs.StorageServer.<init>(StorageServer.java:41)
at org.csource.fastdfs.TrackerClient.getStoreStorage(TrackerClient.java:15
at org.csource.fastdfs.TrackerClient.getStoreStorage(TrackerClient.java:69)
at cn.tianya.fdfs.test.Uploader.run(FDFSTest.java:101)
回复 5# wp00000008
看打印出来的异常信息,是连接storage server失败。
我找出原因了,将storage的配置文件修改了一下
从
tracker_server=127.0.0.1:22122
改为
tracker_server=192.168.100.68:22122
现在错误是:
java.lang.NullPointerException
at java.lang.String.getBytes(String.java:811)
at org.csource.fastdfs.StorageClient.do_upload_file(StorageClient.java:407)
at org.csource.fastdfs.StorageClient.upload_file(StorageClient.java:134)
at org.csource.fastdfs.StorageClient.upload_file(StorageClient.java:105)
at org.csource.fastdfs.StorageClient1.upload_file1(StorageClient1.java:67)
at cn.tianya.fdfs.test.Uploader.run(FDFSTest.java:106)
特别说明:
tracker和storage是在一台机器的
从客户机均能telnet上去
回复 8# wp00000008
昨天我用你的测试代码测试过,碰到的也是NullPointer的异常。
FastDFS Java Client API中有全局变量需要初始化,你要先调用:
ClientGlobal.init(fdfs_client_conf_filename);
或者直接对ClientGlobal的全局变量进行赋值也是可以的。