Socket problems with MT3 API
  #1 (permalink)  
Old 12-29-2005, 08:08 AM
Freshman
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
fxtrader625 is on a distinguished road
Default Socket problems with MT3 API

Hi all,

I am writing an automatic trading system on a website using Microsoft Visual Studio, C#, ASP.NET, MT3APIDotNet.DLL and mtapi.DLL. With an InterbankFX demo account, it works fine when using my local host (on PC). Sometimes, I saw a problem "Invalid Socket Handle" when trying to run this application. It happens sometimes when I did not cleanup sockets (using WSACleanup function) and not disposing API objects, at the end or during debugging this application.

The solution for this moment is that I needed to restart my PC, to get all sockets cleaned up, okay.

But, it is not the best solution for when I moved this application to a commercial server. So, there are still some sockets left hanging, when testing this application there, I still get an exception "Invalid Socket Handle". I cannot ask the provider to restart the whole server to get sockets cleaned up?? So I need to find out how I can get sockets cleaned up.

Can anyone help me to get this resolved? Any experience with sockets?
Thanks for advance,
Jeff
Reply With Quote
  #2 (permalink)  
Old 12-29-2005, 09:16 AM
scorpion's Avatar
Administrator
 
Join Date: Aug 2004
Posts: 1,974
Thanks: 119
Thanked 383 Times in 152 Posts
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Send a message via MSN to scorpion Send a message via Yahoo to scorpion
Default

It is most likely problem inside mtapi.dll provided by MetaQuotes. My code (MT3APIDotNet.DLL) only take error code from mtapi.dll and raise managed exception.

Probably this is caused by the disconnection from mt server, or problably you miss a few calls to Disconnect() or Dispose() in api objects. You can simply reconnect back by first catch the exception, call disconnect() and then connect(). Everything would be just fine.
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #3 (permalink)  
Old 12-29-2005, 12:26 PM
Freshman
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
fxtrader625 is on a distinguished road
Default

Quote:
Originally Posted by scorpion
It is most likely problem inside mtapi.dll provided by MetaQuotes. My code (MT3APIDotNet.DLL) only take error code from mtapi.dll and raise managed exception.

Probably this is caused by the disconnection from mt server, or problably you miss a few calls to Disconnect() or Dispose() in api objects. You can simply reconnect back by first catch the exception, call disconnect() and then connect(). Everything would be just fine.
Well, thanks for your reply, but in a meanwhile, I have just resolved the socket problem. It happens that when I have left already all 10 sockets connected, I got an exception "Cannot create a new socket". From this point, you cannot create a new socket anymore, since all sockets were busy. So, I have added a static function to MT3APIWrapped module, to force socket deletion:

Code:
Public Shared Sub Dispose(ByVal Socket As Integer) MtDelete(Socket) End Sub
After recompiling MT3APIWrapped module, I called this function 10 times, from socket = 1 to 10, then everything works fine.

Jeff
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MT3 API for VB.net and C# scorpion Tools / Utilities 55 09-02-2006 06:02 PM
Correct the BackTest on MT3 (MetaTrader) the robber platforms ssa MetaTrader and ZeroCode 5 08-19-2005 09:22 PM
mt4 api sccz97 MetaTrader and ZeroCode 24 07-30-2005 12:05 PM


All times are GMT. The time now is 10:48 PM.
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0

Registered members have access to special online forex currency trading tools, software, mt4 expert advisors and indicators. Register now

Main Menu

Economic Forecast