5

我正在使用下面此链接上的交易客户端应用程序在我的 VPS 服务器和经纪人服务器之一之间建立连接。

http://www.quickfixn.org/tutorial/example-applications

经过一周的努力,我终于可以粗略地连接到经纪人的服务器了。

但是,当我运行交易客户端应用程序时,在登录阶段我收到此错误:

Unable to write data to the transport connection: An existing connection was forcibly   closed by the remote host

at QuickFix.SocketInitiatorThread.ReadSome(Byte[] buffer, Int32 timeoutMilliseconds) 
in ... SoecketInitiatorThread.cs:line 170 ......

at QuickFix.SocketInitiatorThread.Read() in ... SoecketInitiatorThread.cs:line 80
......

交易客户端应用程序不断重复登录尝试,但是,它始终只收到相同的错误消息。

当然,像我这样的新手在这个 QuickFix/n 引擎上,我真的无法弄清楚出了什么问题。我能想到的一个可能的调查领域是我的 stunnel 证书可能无效,因为我对 stunnel 程序 ( https://www.stunnel.org ) 也很陌生。我只按照网站上的说明使用经纪人的 ip 地址配置 pem 证书,但我不能 100% 确定它的用途。

这是我放在“stunnel.conf”文件中的内容:

[FIXORDER]
client = yes
accept = external ip of VPS : port   eg.(10.160.103.65:22)
connect = broker ip address :port  eg.(102.12.124.9:444)

以下是来自 stunnel 程序的一些记录消息:

2014.11.26 17:23:44 LOG5[3348]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket
2014.11.26 17:23:48 LOG5[760]: Service [FIXORDER] accepted connection from x.xx.xx.xxx:xx
2014.11.26 17:23:48 LOG5[760]: s_connect: connected xxx.x.xx.xxx:xxx
2014.11.26 17:23:48 LOG5[760]: Service [FIXORDER] connected remote server from x.xx.xxx.xxx:xxx
2014.11.26 17:23:48 LOG3[760]: SSL_connect: Peer suddenly disconnected
2014.11.26 17:23:48 LOG5[760]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket

我使用内置的自我证书应用程序使用上面的“stunnel.conf”文件构建了证书。

如您所见,对于像我这样的新手来说,这有点复杂,对此问题的任何想法或提示将不胜感激。

提前非常感谢。

亲切的问候。

==================================================== ================================= 更新于 27/11/2014

在我将调试详细设置为高并接受 xapi1492 的建议后,我正在从 Stunnel 日志文件更新我的错误日志。

2014.11.27 01:10:46 LOG7[944]: Service [FIXORDER] started
2014.11.27 01:10:46 LOG5[944]: Service [FIXORDER] accepted connection from x.xxx.xxx.xxx:3667
2014.11.27 01:10:46 LOG6[944]: s_connect: connecting xx.x.xx.xx:9002
2014.11.27 01:10:46 LOG7[944]: s_connect: s_poll_wait xx.x.xx.102:9002: waiting 10 seconds
2014.11.27 01:10:46 LOG5[944]: s_connect: connected xx.x.xx.xx:9002
2014.11.27 01:10:46 LOG5[944]: Service [FIXORDER] connected remote server from x.xxx.xxx.xxx:3668
2014.11.27 01:10:46 LOG7[944]: Remote socket (FD=392) initialized
2014.11.27 01:10:46 LOG6[944]: SNI: sending servername: xxx.x.xx.xx
2014.11.27 01:10:46 LOG7[944]: SSL state (connect): before/connect initialization
2014.11.27 01:10:46 LOG7[944]: SSL state (connect): SSLv2/v3 write client hello A
2014.11.27 01:10:46 LOG3[944]: SSL_connect: Peer suddenly disconnected
2014.11.27 01:10:46 LOG5[944]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket
2014.11.27 01:10:46 LOG7[944]: Remote socket (FD=392) closed
2014.11.27 01:10:46 LOG7[944]: Local socket (FD=380) closed
2014.11.27 01:10:46 LOG7[944]: Service [FIXORDER] finished (0 left)

==================================================== ================================= 更新于 28/11/2014

仍然很难找到答案,所以我决定为 QuickFix 客户端应用程序提供我的配置文件。

[DEFAULT]
ConnectionType=initiator
ReconnectInterval=2
FileStorePath=store
FileLogPath=fixlog
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=Y
DataDictionary=FIX44.xml
SocketConnectHost= xxx //my vps ip address
SocketConnectPort= xxx //my vps port //specified on stunnel
ResetOnLogon=Y
ResetOnLogout=Y
ResetOnDisconnect=Y
CheckLatency=N
LogonTimeout=10


# standard config elements

[SESSION]
BeginString=FIX.4.4
SenderCompID= xxx   //my ID
Username= xxx       //my username
Password= xxx       //my password
TargetCompID=FIXORDER
HeartBtInt=30
SocketConnectHost= xxx  //my vps ip address
SocketConnectPort= xxx  //my vps port //specified on stunnel
DataDictionary=FIX44.xml

==================================================== ================================= 更新于 28/11/2014

接受xpa1492的建议,我把Borker的IP地址和端口号放在SocketConnectHost和SocketConnectPort上。这是我从 QuickFix 客户端应用程序收到的日志消息。似乎建立了初始连接,但登录请求可能以某种方式无效。

<event> connecting to xxx (ip address of broker); 
<event> connection succeeded; 
<event> session reset: ResetOnLogon; 
<event> session reset ResetSetNumFlag; 
<outgoing> 8=Fix4.4 ...... ; 
<event> initiated logon request; 
<incoming> 8=FIX4.4 .....; 
<event> received logout request; 
<outgoing> 8=FIX4.4 .....; 
<event> sending logout response;

代理发送注销请求时传入消息的详细信息。

<incoming> 8=FIX4.4   9=63   35=5   34=1  49=FIXORDER   52=20141128-02:09:00.495   56=TargetCompID(from acceptor standing point of view=SenderID for me)   10=171
4

1 回答 1

5

FIX 服务器在不喜欢您的第一条消息(始终是登录消息)时断开连接是很常见的。根据您收到的错误,这正是正在发生的事情 - 您连接到服务器,发送登录消息,然后服务器断开连接。

解决问题的正确方法是联系另一端的技术支持并询问他们为什么断开连接。

如果这不可行,您将需要尝试可能出错的地方。根据我的经验,问题通常是序列号(标签 34)不匹配。大多数服务器会保留您发送的最后一个序列号(例如 1),并且在断开连接后希望您发送带有下一个编号的登录消息(在本例中为 2)。尝试从 1 开始并在重新连接之间增加序列号。

另一个可能的问题是错误的 CompID(发送者或目标者)。

更新(sTunnel 和 SSL 证书设置):

服务器可能会断开连接,因为您没有通过 SSL 连接...您的 stunnel.conf 文件需要如下所示:

; Enable debug (7 is the most verbose output)
debug = 7
output = stunnel.log

[FIXORDER]
client = yes
accept = 127.0.0.1:[port number your client connects to]
connect = [fix server ip]:[fix server port]
cert =  xxx_cert.pem
key = xxx_key.pem

请注意,accept可以是 127.0.0.1 或您的 VPS 服务器的 IP,但 127.0.0.1 是首选。然后,您的 Fix 客户端也可以连接到 127.0.0.1(sTunnel 侦听的位置)。

于 2014-11-27T00:38:24.193 回答