QuickFIX/n - Initiator repeatedly throw errors during Logon phase - c#

I am using the trade client application on this link below to make connection between one of my VPS server and brokers server.
http://www.quickfixn.org/tutorial/example-applications .
After one week of struggle, I been able to make a connection to the broker's server finally in loosely speaking.
However, when I run the trade client application, at logon stage I am getting this errors:
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
......
The trade client application is keeping repeating the logon attempt, however, it keeps getting the same error message only.
Of course, with newbie like me on this QuickFix/n engine, I am really unable to figure out what went wrong. One possible area of investigation I can think of is that my stunnel certificate may be invalid as I am also very new to stunnel program (https://www.stunnel.org). I only followed the instruction from website to configure pem certificate with broker's ip address but I am not 100% sure about its purpose though.
Here is what I put on the "stunnel.conf" file:
[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)
Here is some record of logged message from stunnel program:
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
I built certificate using above "stunnel.conf" file using built in self certificate application.
As you see, it is kind of complicated for newbie like me, any thought or tips on this problem will be really appreciated.
Thanks so much in advance.
Kind regards.
M
==================================================================================
Updated on 27/11/2014
Here I am updating my error log from Stunnel log file after I set debug verbose high taking the suggestion from xapi1492.
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)
==================================================================================
Updated on 28/11/2014
Still having difficult to find answer, so I decided to provide my config file for QuickFix client application.
[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
==================================================================================
Updated on 28/11/2014
Taking suggestion from xpa1492, I put Borker's IP address and port number on SocketConnectHost
and SocketConnectPort. Here is the log message I am getting from my QuickFix Client Application.
It seems that initial connection is made but maybe logon request is not valid somehow.
<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;
Details of incoming message from brokers when they send logout request.
<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

It is very common for FIX servers to drop connections when they don't like something about your first message (which is always the logon message). Based on the error you are getting, this is exactly what is happening - you connect to the server, send the Logon message and then the server drops the connection.
The right way to solve the issue is to contact tech support on the other end and ask them why they are dropping the connection.
If this is not feasible, you will need to experiment with what might be wrong. In my experience, the problem is often a mismatch in the sequence numbers (tag 34). Most servers would maintain the last sequence number you sent (say 1) and after a disconnect would expect you to send your Logon message with the next number (2 in this example). Try starting from 1 and incrementing the seq number between reconnects.
Another possible issue is wrong CompIDs (Sender or Targer).
UPDATE (sTunnel and SSL certificate setup):
It is possible that the server drops the connection because you are not connecting over SSL... You stunnel.conf file needs to look like this:
; 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
Note that accept can be 127.0.0.1 or the IP of your VPS server, but 127.0.0.1 is the preferred choice. Your Fix client can then also just connect to 127.0.0.1 (where sTunnel listens).

Related

Syntax error, command unrecognized. The server response was ''

I've looked at 3 or 4 questions here so far and they haven't helped yet.
I have set up SmarterMail 14.x on a client's machine. I know very little about setting up mail servers (I don't know why he thinks I do) but I have it installed, a domain set up pointing to the MX record, the port open (9998) and I am able to send email just fine from the web interface.
However, I can't send email from Sql or from C#. I created a quick and dirty app to allow me to enter the server, port, credentials, and to/from and I get this response every time:
[Inner Exception]
Unable to connect to the remote server
[Details]
System.Net.Mail.SmtpException: Failure sending mail. ---> > System.Net.WebException: Unable to connect to the remote server ---> > System.Net.Sockets.SocketException: No connection could be made because the > target machine actively refused it 204.12.49.188:25
I've tried multiple logins. I've also confirmed that SMTP is turned on and IMAP/POP3 is turned off. I'd post images of it but unfortunately I can't yet.
The code to send is below and it is about as simple as it gets:
SmtpClient client = new SmtpClient(ServerTextBox.Text, Convert.ToInt32(PortTextBox.Text));
NetworkCredential login = new NetworkCredential(UsernameTextBox.Text, PasswordTextBox.Text);
client.Credentials = login;
MailMessage message = new MailMessage(FromTextBox.Text, ToTextBox.Text, "Wine and Spirits Jobs Alerts", "Below are this week's job alerts: There are no job alerts at this time");
client.SendCompleted += HandleSendCompleted;
client.SendAsync(message, null);
I've also tried it locally on their VPS and on my machine. I've turned on and off the firewall and I've got a specific rule allowing outgoing traffic on 9998 (and you can log into the web interface remotely) so this isn't a matter of being able to contact it.
I'm at a loss of what to do. If someone can help??
EDIT: It's clear I was using the wrong port - 9998 instead of 25. Using port 25 now tells me either time out or that it was actively refused. The firewall does have specific rules for port 25 that allow all traffic, so it shouldn't be stopped.
EDIT 2: I've re-created the MX record on the domain and ensured it is pointing to the correct IP address. I've also re-created the domain in Smartermail and made sure SMTP is turned on, authentication is required, SSL is not, POP and IMAP are turned off, and that my login is correct. I've also tried turning on and off the firewall. No dice.
I finally solved the issue.
It had nothing to do with firewalls or the MX record or using/not using an IP address and everything to do with the fact that while port 25 was indeed assigned to SMTP and SMTP was indeed turned on, the IP address of the domain itself was NOT assigned to the SMTP configuration so SmarterMail wasn't actually monitoring the port.
Problem solved - email sends. Fun stuff! Thank you for everyone's responses!
Try setting SMTP mail server IP address in your mail sending code.
SmtpMail.SmtpServer = "your mail server name or IP address goes here";
SmtpMail.Send(Message);
Your can set this property at global level or in any Initialization code.
Reference : https://msdn.microsoft.com/en-us/library/system.web.mail.smtpmail%28v=vs.110%29.aspx

SQL Server Connection Issue - I can connect but other users can't

[edit] so not sure what happened, but we ended up resetting the server and turning off/on TCP/IP and Named Pipes and after a restart and updating the settings everything started working again. weirdest thing. anyways thanks for the help guys.
I'm building a C# WPF application for my job, and I'm getting a weird problem that I've been trying to figure out for the past week. The application connects to the server and imports several tables on start up. So I built it out and was testing it with no issues, but when i pass it to our testers, and everyone is getting the following errors:
Provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
The users are able to connect to the server through other methods (SSMS/Excel VBA), but just through the application it won't work.
I've checked the following:
Remote connections enabled
TCP/IP connections enabled
Firewall settings are the exact same across all users (me included)
application is compiled as 32 bit (saw this in another thread)
We're using SQL Server 2008 and I've tried several connection strings/methods.
below is the code I'm using to connect:
public void Open_DB_Conn(string Connection_Str)
{
try
{
Sql_Conn = new SqlConnection(Conn_Str);
Sql_Conn.Open();
}
catch (Exception e)
{
MessageBox.Show(string.Format("Error Message:{0} Conn String: {1}",e.Message,Conn_Str));
}
}
Below is my connection string (this is just one of many iterations I've used trying to get it working):
Data Source=IP Address;Initial Catalog=DB_Name;User ID=LOGIN;Password=PWD
Anyone know why I would be the only one able to get it to work and that the users are able to login to the server using other applications without a problem? They use it for logging their excel VBA scripts and there aren't any issues there.
Try this - it may be your answer
"The error is reported by client library. While your server is listeing on remote TCP, client will still try TCP and NP connection in order. So the error client behavior is expected. From what you have described, I believe that even though you enabled the remote TCP connection on the XPSP2 machine, you didn't make the TCP listening port an exception of XPSP2 personal firewall. You should follow steps below to resolve this issue.
check the SQL Server Errorlog to make sure SQL Server is now listening on TCP/IP and confirm which port it is listening on. Usually 1433. In the Errorlog, you will see several lines that discuss what SQL Server is listening on. Below is an example:
2006-01-04 01:41:07.65 server SQL server listening on 10.254.1.150: 1433. <--Shows the IP Address and the port.
2006-01-04 01:41:07.65 server SQL server listening on 127.0.0.1: 1433. <--Shows another IP Address and the port.
2006-01-04 01:41:07.69 server SQL server listening on TCP, Shared Memory, Named Pipes.
2006-01-04 01:41:07.69 server SQL Server is ready for client connections
2, Make sure on Windows XP that the firewall is not blocking that port.
3, go to your client machine and run the client network configuration tool (cliconfg.exe) Make sure TCP/IP is enabled, click properties and make sure the port number is the same one as SQL Server is listening on. Here you can enable NP or disable client NP as well.
Once both the client and the server are using TCP/IP with the same port number and the firewall on server machines is not blocked, you should be able to connect.
Hope this helps."
(Ref: http://social.technet.microsoft.com/Forums/sqlserver/en-US/c488cf76-2515-440f-b3f8-9cfad689c5b6/named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server?forum=sqldataaccess)
You have to configured your SQl server so that other IP can connect it for that you have to gone through mentioned link
Configure SQL server
What authentication are you using for the SQL Server? Windows Authentication or SQL Server authentication? My suggestion is to first turn on SQL Server authentication and use the sa\password to connect to the server. If you are successful, then ask the others (users of your application) to try with the same connection string. Let me know what you find out.
Be sure that the port specified in:
Data Source="IPAddress,port";Initial Catalog=DB_Name;User ID=LOGIN;Password=PWD
matches the port on your SQL Server. You can check that by going on SQL Server COnfiguration Manager and viewing TCP/IP properties.
EDIT :
It is also the case the port defined by blocked by an external firewall. And the rest Applications use other ports. Try to find out which port you can use (if indeed the are restrictions to your network)
Make sure your SQL Server instance is properly configured to use TCP using Sql Server Configuration Manager.
It is by default disabled in SQL Express, as show below.
I'd like to know more about your "Sql_Conn" class.
Also, try using this for your connection.
using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
string cmdText = "SELECT name FROM sys.tables"
cmd.CommandText = cmdText;
cmd.ExecuteNonQuery();
}
}

What are the possible reasons of SocketError.ConnectionReset in TCP Socket

I have a TCP socket based client server system.
Everything works fine but when network is disconnected form client end and reconnect it again i get automatically SocketError.ConnectionReset send form client and regarding this command the socket is closed in the server side. this is also fine.
but when i look in to the client side it shows the socket is still connected with server. (regarding socket is still connected with server [It does not happen every time], sometime it shows disconnected and some times shows connected)
Does it make sense that "server get a SocketError.ConnectionReset from
client end but client is still connected"?
So i want to know what is the possible reasons of SocketError.ConnectionReset and how to handle such type of problem i have mentioned?
Again i say, Everything is working fine in normal environment (e.g if i exit the client it is disconnected the socket same for the server)
Thanks in advance.
EDIT:
Here is the code in the client side. actually it's a timer that tick every 3 second through programs lifetime and check if Socket is connected or not if its disconnected then it tries to reconnect again through a new socket instance
private void timerSocket_Tick(object sender, EventArgs e)
{
try
{
if (sck == null || !sck.Connected)
{
ConnectToServer();
}
}
catch (Exception ex)
{
RPLog.WriteDebugLog("Exception occcured at: "+ System.Reflection.MethodBase.GetCurrentMethod().ToString()+"Message: "+ex.Message);
}
}
In normal situation (without network disconnect/reconnect) if TCP server get a
SocketError.ConnectionReset form any client, in the client side i see
clients socket is disconnected and it tries to reconnect it again
through the code shown. but when situation happen explained earlier,
server gets a SocketError.ConnectionReset but client shows it still
connected. though the TCP server shows the reset command is send form the exact client
side.
There are several causes but the most common is that you have written to a connection that has already been closed but he other end. In other words, an application protocol error. When it happens you have no choice but to close the socket, it is dead. However you can fix the underlying cause.
When discussing a TCP/IP issue like this, you must mention the network details between the client and the server.
When one side says the connection is reset, it simply means that on the wire a RST packet appears. But to know who sends the RST packet and why, you must utilize network packet captures (by using Wireshark and any other similar tools),
https://en.wikipedia.org/wiki/Transmission_Control_Protocol
You won't easily find out the cause at .NET Framework level.
The problem with using Socket.Connected as you are is that it only gives you the connected state as at the last Send or Receive operation. i.e. It will not tell you that the socket has disconnected unless you first try to send some data to it or receive data from it.
From MSDN description of the Socket.Connected property:
Gets a value that indicates whether a Socket is connected to a remote host as of the last Send or Receive operation.
So in your example, if the socket was functioning correctly when you last sent or received any data from it, the timerSocket_Tick() method would never call ConnectToServer(), even if the socket was now not connected.
how to handle such type of problem i have mentioned?
Close the socket and initiate a new connection.

C# : SMTP error

i am creating an email client that sends e-mail address from server ip instead of SMTP , i wrote the following code:
SmtpClient server = new SmtpClient();
server.Host= "50.23.128.66";
server.Port = 25;
server.Send("from#yahoo.com", "to#yahoo.com", "hi", "hope it works");
but when i run it, i get that error:
Unhandled Exception: System.Net.Mail.SmtpException: Service not
available, closing transmission channel. The server response was:
Cannot connect to SMTP server
50.23.128.66 (50.23.128.66:25), connect error 10061
i actually think that port is wrong . * By the way i am using Windows Server 2008 *
I think "connect error 10061" is the same as errno == ECONNREFUSED on a POSIX platform, which means the connection did not succeed, probably because the host you tried to connect to isn't running any sort of server on port 25.
According to this SMTP Server Test the server is not open to receiving connections on port 25:
No connection could be made because the target machine actively refused it 50.23.128.66:25
It's possible the server uses some form of encryption, and you will have to connect on one of the "secure" SMTP ports.
Are you sure it's an SMTP server, and not an IMAP server or the like?

How to get status of socket when network cable disconnect from network adapter

I write a comunication program with c/s mode in C# ,server and client program on different computer. Today after client progarm connected to server progarm ,then I pulled out cable from network adapter (after this , client and server program didn't do anything), stranger thing happened. I found out socket of server program still keep connected status. and I use command "netstat -a -n" to retrieve network information ,and get information like following :
TCP 192.168.1.2:3645 192.168.1.3:1863 ESTABLISHED
192.168.1.2 (Server IP Address)
192.168.1.3 (Client IP Address)
Do anyone know the reason ? how to solve this problem .
I wanna how server program can receive the event and close the socket when network cable of client computer has been pulled out.
Please give me some advices or solutions.
Thanks
I think it can be solved by using TCP keepalive.
refrencehttp://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html
after connecting , set socket keepalive property . msdn say this switch default status is off , if set keepalive to on , socket will check the network status automaticly , and first check time is 2 hours after last operation on socket. but the time can be adjsut to short . then after first check , socket will servral times. if connection is down or died,
socket will throw exception .
C# Source:
uint dummy = 0;
byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
//set keepalive on
BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);
//interval time between last operation on socket and first checking. example:5000ms=5s
BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));
//after first checking, socket will check serval times by 1000ms.
BitConverter.GetBytes((uint)1000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);
Socket socket = __Client.Client;
socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
I have checked. It's running ok.
You can't.
The only reliable way to check connected status is to send data over the wire, so: Deal with connection failures during send/receive, and, optionally, periodically check for connection status by some form of ping, if you want connection status during idle periods.
Im a bit unsure but if you try to read data from the socket after you pulled the cable it will tell you that its not connected any more..

Categories

Resources