C# QuickFIX/n-启动器在登录阶段重复抛出错误

C# QuickFIX/n-启动器在登录阶段重复抛出错误,c#,c++,quickfix,fix-protocol,quickfixj,C#,C++,Quickfix,Fix Protocol,Quickfixj,我正在使用下面这个链接上的交易客户端应用程序在我的一个VPS服务器和代理服务器之间建立连接 经过一周的努力,我终于能够连接到代理的服务器了 但是,当我运行trade client应用程序时,在登录阶段我会遇到以下错误: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host at QuickFix.SocketInitia

我正在使用下面这个链接上的交易客户端应用程序在我的一个VPS服务器和代理服务器之间建立连接

经过一周的努力,我终于能够连接到代理的服务器了

但是,当我运行trade client应用程序时,在登录阶段我会遇到以下错误:

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程序()也非常陌生。我只是按照网站上的说明用代理的ip地址配置pem证书,但我不能100%确定它的用途

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

以下是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”文件和内置的自证书应用程序构建了证书

[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
正如你所看到的,对于像我这样的新手来说,这有点复杂,任何关于这个问题的想法或建议都将不胜感激

非常感谢

亲切的问候

M

================================================================================== 更新日期:2014年11月27日

在这里,我根据xapi1492的建议将debug verbose设置为高后,从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)
================================================================================== 更新日期:2014年11月28日

仍然很难找到答案,所以我决定为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
================================================================================== 更新日期:2014年11月28日

根据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;
连接到xxx(代理的ip地址);
连接成功;
会话重置:ResetOnLogon;
会话重置ResetSetNumFlag;
8=固定4.4;
启动登录请求;
8=固定值4.4。。。。。;
收到注销请求;
8=固定值4.4。。。。。;
发送注销响应;
代理发送注销请求时收到的消息的详细信息

<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
8=FIX4.49=6335=534=149=FIXORDER 52=20141128-02:09:00.49556=TargetCompID(从接受者的角度来看=我的发送者)10=171

当修复服务器不喜欢您的第一条消息(始终是登录消息)时,通常会断开连接。根据您收到的错误,这正是发生的情况-您连接到服务器,发送登录消息,然后服务器断开连接

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

如果这是不可行的,你将需要尝试什么可能是错误的。根据我的经验,问题通常是序列号不匹配(标签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是首选。然后,您的修复客户端也可以连接到127.0.0.1(sTunnel收听的地方)。

我通过在sTunnel程序的日志文件中添加一些录制的消息来编辑我的问题。希望问题本身现在更清楚了。真的谢谢你的更新好答案。只是好奇我们是否可以随机分配这个[您的客户端连接到的端口号]?我必须首先使用扫描仪来查找空闲端口吗?另外,我在哪里可以获得xxx_cert.pem和xxx_key.pem?我搜索了stunnel文件夹,但有3个其他pem文件,但不是用于FIXORDER的文件。如果服务器需要SSL,则他们需要为您提供正确的密钥和证书。如果他们没有(这通常是QA/UAT环境的情况),那么您可能不需要SSL。您可以使用任何您想要的端口(只要它不被任何其他应用程序使用)。一般认为最多1024个端口是保留的,所以您应该使用1024个以上的端口(冲突非常罕见)。同样非常好,非常清楚。我的经纪人在开始时没有向我提供密钥和证书。因此,我假设我将需要SSL。然后,仍然很难看到“cert=xxx\u cert.pem”和“key=xxx\u key.pem”来自何方。在我的stunnel文件夹中,我只有peer-gmail-imap.pem和peer-gmail-pop3.pem和stunnel.pem。我用记事本打开了这些文件,它们都是加密代码,很难阅读。关于我的问题,我如何为[FIXORDER]生成xxx_cert.pem和xxx_key.pem?再次感谢您的帮助。:)在我将“debug=7”和“output=Stunnel.log”放在配置文件中之后,我还从最新的Stunnel日志文件中添加了一些日志消息。我希望这能解决我现在的问题。SSL状态(connect)后突然断开与服务器的连接:SSLv2/v3写入客户端hello A。对于像我这样的非网络It人员来说,这真的很混乱,很难理解。:)