// ImportNetEventsProcDLL.mqh#import "NetEventsProcDLL.dll"// Only for Clients:int ConnectTo(uchar& ps8_ServerIP[], // in - string ps8_ServerIP = "0123456789123456"int s32_Port, // in int& ph_Client[]); // out - int ph_Client[1]int ConnectClose(int h_Client); // in//// Only for Server:int ServerOpen(int s32_Port); // inint GetAllConnections(int& ph_Client[], // out - int ph_Client[62]int& ps32_ClientIP[], // out - int ps32_ClientIP[62]int& ps32_ClientCount[]); // out - int ps32_ClientCount[1]int DisconnectClient(int h_Client); // inint ServerClose();
//// For both: Clients and Serverint SendToInt (int h_Client, // inint& ps32_SendBuf[], // inint s32_SendBufLen); // in - SendBuf[] array size in int element int SendToDouble(int h_Client, // indouble& pd_SendBuf[], // inint s32_SendBufLen); // in - SendBuf[] array size in double element int SendToString(int h_Client, // inuchar& ps8_SendBuf[], // inint s32_SendBufLen); // in - SendBuf string size in char element int ReadFromInt (int h_Client, // inint& ps32_ReadBuf[], // in int s32_ReadBufLen, // in - ReadBuf[] array size in int elementint& ps32_ReadLen[]); // out - int ps32_ReadLen[1] - count of actually read data in int elementint ReadFromDouble(int h_Client, // indouble& pd_ReadBuf[], // inint s32_ReadBufLen, // in - ReadBuf[] array size in double elementint& ps32_ReadLen[]); // out - int ps32_ReadLen[1] - count of actually read data in double elementint ReadFromString(int h_Client, // instring ps8_ReadBuf, // inint s32_ReadBufLen, // in - ReadBuf string size in char elementint& ps32_ReadLen[]); // out - int ps32_ReadLen[1] - count of actually read data in char element// #import
//***************************************************************************************#define WSAEINTR 1004#define WSAEBADF 1009#define WSAEACCES 10013#define WSAEFAULT 10014#define WSAEINVAL 10022#define WSAEMFILE 10024#define WSAEWOULDBLOCK 10035#define WSAEINPROGRESS 10036#define WSAEALREADY 10037#define WSAENOTSOCK 10038#define WSAEDESTADDRREQ 10039#define WSAEMSGSIZE 10040#define WSAEPROTOTYPE 10041#define WSAENOPROTOOPT 10042#define WSAEPROTONOSUPPORT 10043#define WSAESOCKTNOSUPPORT 10044#define WSAEOPNOTSUPP 10045#define WSAEPFNOSUPPORT 10046#define WSAEAFNOSUPPORT 10047#define WSAEADDRINUSE 10048#define WSAEADDRNOTAVAIL 10049#define WSAENETDOWN 10050#define WSAENETUNREACH 10051#define WSAENETRESET 10052#define WSAECONNABORTED 10053#define WSAECONNRESET 10054#define WSAENOBUFS 10055#define WSAEISCONN 10056#define WSAENOTCONN 10057#define WSAESHUTDOWN 10058#define WSAETOOMANYREFS 10059#define WSAETIMEDOUT 10060#define WSAECONNREFUSED 10061#define WSAELOOP 10062#define WSAENAMETOOLONG 10063#define WSAEHOSTDOWN 10064#define WSAEHOSTUNREACH 10065#define WSAENOTEMPTY 10066#define WSAEPROCLIM 10067#define WSAEUSERS 10068#define WSAEDQUOT 10069#define WSAESTALE 10070#define WSAEREMOTE 10071#define WSASYSNOTREADY 10091#define WSAVERNOTSUPPORTED 10092#define WSANOTINITIALISED 10093#define WSAEDISCON 10101#define WSAENOMORE 10102#define WSAECANCELLED 10103#define WSAEINVALIDPROCTABLE 10104#define WSAEINVALIDPROVIDER 10105#define WSAEPROVIDERFAILEDINIT 10106#define WSASYSCALLFAILURE 10107#define WSASERVICE_NOT_FOUND 10108#define WSATYPE_NOT_FOUND 10109#define WSA_E_NO_MORE 10110#define WSA_E_CANCELLED 10111#define WSAEREFUSED 10112#define WSAHOST_NOT_FOUND 11001#define WSATRY_AGAIN 11002#define WSANO_RECOVERY 11003#define WSANO_DATA 11004#define WSA_IO_PENDING 997#define WSA_IO_INCOMPLETE 996#define WSA_INVALID_HANDLE 6#define WSA_INVALID_PARAMETER 87#define WSA_NOT_ENOUGH_MEMORY 8#define WSA_OPERATION_ABORTED 995#define ERROR_INVALID_PARAMETER 88//change to 88 due to conflict#define INADDR_NONE 0xffffffff#define ERROR_TIMEOUT 1460#define OK 0// Get a human readable error message for an API error codestring GetErrMsg(uint s32_Errors)
{
// Some translations of error codes are really stupid --> show the original error code.string s_NoExplanationYet = " - We have no yet explanation for this error";
switch (s32_Errors)
{
case WSAEINTR: return("WSAEINTR");
case WSAEBADF: return("WSAEBADF");
case WSAEACCES: return("WSAEACCES");
case WSAEFAULT: return("WSAEFAULT");
case WSAEINVAL: return("WSAEINVAL");
case WSAEMFILE: return("WSAEMFILE");
case WSAEWOULDBLOCK: return("WSAEWOULDBLOCK");
case WSAEINPROGRESS: return("WSAEINPROGRESS");
case WSAEALREADY: return("WSAEALREADY");
case WSAENOTSOCK: return("WSAENOTSOCK");
case WSAEDESTADDRREQ: return("WSAEDESTADDRREQ");
case WSAEMSGSIZE: return("WSAEMSGSIZE");
case WSAEPROTOTYPE: return("WSAEPROTOTYPE");
case WSAENOPROTOOPT: return("WSAENOPROTOOPT");
case WSAEPROTONOSUPPORT: return("WSAEPROTONOSUPPORT");
case WSAESOCKTNOSUPPORT: return("WSAESOCKTNOSUPPORT");
case WSAEOPNOTSUPP: return("WSAEOPNOTSUPP");
case WSAEPFNOSUPPORT: return("WSAEPFNOSUPPORT");
case WSAEAFNOSUPPORT: return("WSAEAFNOSUPPORT");
case WSAEADDRINUSE: return("WSAEADDRINUSE");
case WSAEADDRNOTAVAIL: return("WSAEADDRNOTAVAIL");
case WSAENETDOWN: return("WSAENETDOWN");
case WSAENETUNREACH: return("WSAENETUNREACH");
case WSAENETRESET: return("WSAENETRESET");
case WSAECONNABORTED: return("WSAECONNABORTED");
case WSAECONNRESET: return("WSAECONNRESET");
case WSAENOBUFS: return("WSAENOBUFS");
case WSAEISCONN: return("WSAEISCONN");
case WSAENOTCONN: return("WSAENOTCONN");
case WSAESHUTDOWN: return("WSAESHUTDOWN");
case WSAETOOMANYREFS: return("WSAETOOMANYREFS");
case WSAETIMEDOUT: return("WSAETIMEDOUT");
case WSAECONNREFUSED: return("WSAECONNREFUSED");
case WSAELOOP: return("WSAELOOP");
case WSAENAMETOOLONG: return("WSAENAMETOOLONG");
case WSAEHOSTDOWN: return("WSAEHOSTDOWN");
case WSAEHOSTUNREACH: return("WSAEHOSTUNREACH");
case WSAENOTEMPTY: return("WSAENOTEMPTY");
case WSAEPROCLIM: return("WSAEPROCLIM");
case WSAEUSERS: return("WSAEUSERS");
case WSAEDQUOT: return("WSAEDQUOT");
case WSAESTALE: return("WSAESTALE");
case WSAEREMOTE: return("WSAEREMOTE");
case WSASYSNOTREADY: return("WSASYSNOTREADY");
case WSAVERNOTSUPPORTED: return("WSAVERNOTSUPPORTED");
case WSANOTINITIALISED: return("WSANOTINITIALISED");
case WSAEDISCON: return("WSAEDISCON");
case WSAENOMORE: return("WSAENOMORE");
case WSAECANCELLED: return("WSAECANCELLED");
case WSAEINVALIDPROCTABLE: return("WSAEINVALIDPROCTABLE");
case WSAEINVALIDPROVIDER: return("WSAEINVALIDPROVIDER");
case WSAEPROVIDERFAILEDINIT: return("WSAEPROVIDERFAILEDINIT");
case WSASYSCALLFAILURE: return("WSASYSCALLFAILURE");
case WSASERVICE_NOT_FOUND: return("WSASERVICE_NOT_FOUND");
case WSATYPE_NOT_FOUND: return("WSATYPE_NOT_FOUND");
case WSA_E_NO_MORE: return("WSA_E_NO_MORE");
case WSA_E_CANCELLED: return("WSA_E_CANCELLED");
case WSAEREFUSED: return("WSAEREFUSED");
case WSAHOST_NOT_FOUND: return("WSAHOST_NOT_FOUND");
case WSATRY_AGAIN: return("WSATRY_AGAIN");
case WSANO_RECOVERY: return("WSANO_RECOVERY");
case WSANO_DATA: return("WSANO_DATA");
case WSA_IO_PENDING: return("WSA_IO_PENDING");
case WSA_IO_INCOMPLETE: return("WSA_IO_INCOMPLETE");
case WSA_INVALID_HANDLE: return("WSA_INVALID_HANDLE");
case WSA_INVALID_PARAMETER: return("WSA_INVALID_PARAMETER");
case WSA_NOT_ENOUGH_MEMORY: return("WSA_NOT_ENOUGH_MEMORY");
case WSA_OPERATION_ABORTED: return("WSA_OPERATION_ABORTED");
case ERROR_INVALID_PARAMETER: return("ERROR_INVALID_PARAMETER");
case INADDR_NONE: return("INADDR_NONE");
case ERROR_TIMEOUT: return("ERROR_TIMEOUT");
case OK: return("OK");
default:
return (DoubleToStr(s32_Errors,0)+s_NoExplanationYet);
}
}
// Convert DWORD IP to string IPstring FormatIP(int IP)
{
int s32_Byte0 = 0x000000FF & IP;
int s32_Byte1 = 0x000000FF & (IP>>8);
int s32_Byte2 = 0x000000FF & (IP>>16);
int s32_Byte3 = 0x000000FF & (IP>>24);
return(DoubleToStr(s32_Byte0,0)+"."+
DoubleToStr(s32_Byte1,0)+"."+
DoubleToStr(s32_Byte2,0)+"."+
DoubleToStr(s32_Byte3,0));
}
Dear Sergey,
Above is the source code for the client.mq4 and ImportNetEventsProcDLL.mqh that I am using.
Here is EA that works as client, I tested - it sends and recieves.
Because now we have no any ticks(market is closed) I introduced Timer to call OnTick() function.
Please test and give me feedback.
Regards,
Sergey
Dear Sergey,
After tried your demo working. I am shifting my work to communicate between your metatrader4 (client) code with my custom C++ application (server).
My C++ application (server) is written in QT and the network module used is QT QTCPSocket and QTCPServer. (*fyi not your library)
The data transfer is successful from the metatrader 4 using your code to my C++ application.
However, the data transfer is not successful from my C++ application to the metatrader 4.
The metatrader4 code seems to not receive any data because the variable ps32_ReadLen display 0 while communicating with my C++ application.
Some of my observation:
At the metatrader 4 client execution, the ReadFromDouble return code is 0, and the ps32ReadLen[0] value is 0 as well. According to your material above, it means there is no data in the client stack with specified handle.
However,I have double checked my C++ TCP server whereby, another TCP client can receive the data.
Some of my test:
I test my C++ TCP server using a 3rd party software SocketTest v 3.0.0
When the SocketTest(client) send "HelloServer", the server will resend back "888999000" as shown above. So i assume the TCP server has no problem sending out messages.
I use the 3rd party software to simulate as TCP server and tries to send messages to the metatrader4 client.
But the variable ps32_ReadLen[0] value displays 0. This variable does display 1 when use your server.
The question I would like to ask is whether your metatrader 4 code can work with other C++ application.
If can, do you have any idea or any advise to me to solve the problem above?
After tried your demo working. I am shifting my work to communicate between your metatrader4 (client) code with my custom C++ application (server).
My C++ application (server) is written in QT and the network module used is QT QTCPSocket and QTCPServer. (*fyi not your library)
The data transfer is successful from the metatrader 4 using your code to my C++ application.
However, the data transfer is not successful from my C++ application to the metatrader 4.
The metatrader4 code seems to not receive any data because the variable ps32_ReadLen display 0 while communicating with my C++ application.
Metatrader 4 ReadFromDouble Code:
Some of my observation:
At the metatrader 4 client execution, the ReadFromDouble return code is 0, and the ps32ReadLen[0] value is 0 as well. According to your material above, it means there is no data in the client stack with specified handle.
However,I have double checked my C++ TCP server whereby, another TCP client can receive the data.
The question I would like to ask is whether your metatrader 4 code can work with other C++ application.
If can, do you have any idea or any advise to me to solve the problem above?
Thanks.
DLL (Dynamic Link Library) functions is universal mean to exchange info between any programs independantly on lang in which they were developed.
One only thing is important - every lang has it's own rules to call DLL fuctions, that's all.
So if you use mine DLL interface you have no any problems.
Yes it can, but MT4 client must know your c++ server protocol, besides look at how MT4 DLL functions must be dtfined:
#import "NetEventsProcDLL.dll"// Only for Clients:int ConnectTo(uchar& ps8_ServerIP[], // in - string ps8_ServerIP = "0123456789123456"int s32_Port, // in int& ph_Client[]); // out - int ph_Client[1]int ConnectClose(int h_Client); // in//// Only for Server:int ServerOpen(int s32_Port); // inint GetAllConnections(int& ph_Client[], // out - int ph_Client[62]int& ps32_ClientIP[], // out - int ps32_ClientIP[62]int& ps32_ClientCount[]); // out - int ps32_ClientCount[1]int DisconnectClient(int h_Client); // inint ServerClose();
//// For both: Clients and Serverint SendToInt (int h_Client, // inint& ps32_SendBuf[], // inint s32_SendBufLen); // in - SendBuf[] array size in int element int SendToDouble(int h_Client, // indouble& pd_SendBuf[], // inint s32_SendBufLen); // in - SendBuf[] array size in double element int SendToString(int h_Client, // inuchar& ps8_SendBuf[], // inint s32_SendBufLen); // in - SendBuf string size in char elementint ReadFromInt (int h_Client, // inint& ps32_ReadBuf[], // in int s32_ReadBufLen, // in - ReadBuf[] array size in int elementint& ps32_ReadLen[]); // out - int ps32_ReadLen[1] - count of actually read data in int elementint ReadFromDouble(int h_Client, // indouble& pd_ReadBuf[], // inint s32_ReadBufLen, // in - ReadBuf[] array size in double elementint& ps32_ReadLen[]); // out - int ps32_ReadLen[1] - count of actually read data in double elementint ReadFromString(int h_Client, // inuchar& ps8_ReadBuf[], // inint s32_ReadBufLen, // in - ReadBuf string size in char elementint& ps32_ReadLen[]); // out - int ps32_ReadLen[1] - count of actually read data in char element// #import
//***************************************************************************************
After connection is established your MT4 client should use this funtions for info exchange with your c++ server, something like that:
uchar uca_ReadBuffer[1000];
int s32_ReadBufLen = 1000;
int s32a_ReadLen[1];
uint u32_Error;
string msw_Buffer = "";
u32_Error = ReadFromString(h_Client, uca_ReadBuffer, s32_ReadBufLen,s32a_ReadLen);
if (u32_Error == OK && s32a_ReadLen[0] != 0)
{
msw_Buffer = CharArrayToString(uca_ReadBuffer,0,s32a_ReadLen[0]);
}
uchar uca_SendBuffer[];
int s32_SendBufLen;
uint u32_Error;
string msw_Buffer = "Text to send";
StringToCharArray(msw_Buffer,uca_SendBuffer);
s32_SendBufLen = StringLen(msw_Buffer);
u32_Error = SendToString(h_Client,uca_SendBuffer,s32_SendBufLen);
if (u32_Error != 0)
{
....
}
Yes it can, but MT4 client must know your c++ server protocol, besides look at how MT4 DLL functions must be dtfined:
After connection is established your MT4 client should use this funtions for info exchange with your c++ server, something like that:
I tested this java client/server.
Results are:
1. MT4 client can connect to it
2. MT4 client can send info to it and he recieves this info
2. MT4 client does't recieve info from this java client/server - the reason is my software is designed to send/recieve data blocks with variable length,
data block length is contained in the 4 bytes header, so MT4 client don't read it's data from stack until data length equal to number in 4 bytes header,
but in the case when java server send only character strings this number is very very very large !
So I should redo some things in my sofware for you to use it, or you should form data length four bytes header for every data block to send to MT4 terminal.
In other words MT4 client and it's software environment waits input data in format : DWORD, Data. DWORD - is 4 bytes header that comtains number of data itself + 4.
Hi michaelt4268 !
The problem is NetEventsProcDLL.dll functions are designed to work with ANSI string but new MT4 works with UNICODE string.
For your separate example you should manage in such way:
For MT4 - correct:
1.
#import "NetEventsProcDLL.dll"
// Only for Clients:
int ConnectTo(uchar& ps8_ServerIP[], // in - string ps8_ServerIP = "0123456789123456"
int s32_Port, // in
int& ph_Client[]); // out - int ph_Client[1]
...
...
...
#import
2. Before call to ConnectTo(...)
make conversion UNICODE string to ANSI string:
uchar uc_ServerIP[];
StringToCharArray(ps8_ServerIP, uc_ServerIP);
and now you can connect to server -
s32_Error = ConnectTo(uc_ServerIP, s32_Port, ph_Client);
3. NetEventsProcDLL.mgh
correct this line -
was - string GetErrMsg(int ps32_Error)
needed so - string GetErrMsg(uint ps32_Error)
You example should work after that, but other examples should be corrected this way too.
Besides include NetEventsProcDLL.dll functions defitnition c++ file must be corrected for another examples.
Regards
Sergey
Dear Sergey,
Very much thanks. I successfully connect to the server after changing what you mentioned above.
And the metatrader4(client) also writes Double datatype successfully to echoserver as shown below.
However, the metatrader4(client) fails to read from the echoserver.
I check the ps32ReadLen[0] value which is 0 as shown below. If I understand correctly, no int elements have been read.
Pleas advise. dear experts here.
Dear Sergey,
Very much thanks. I successfully connect to the server after changing what you mentioned above.
And the metatrader4(client) also writes Double datatype successfully to echoserver as shown below.
However, the metatrader4(client) fails to read from the echoserver.
I check the ps32ReadLen[0] value which is 0 as shown below. If I understand correctly, no int elements have been read.
Pleas advise. dear experts here.
Hi amigo.
Please send me your MT4 client EA, something wrong in it, I'll look at.
Regards,
Sergey
Hi amigo.
Please send me your MT4 client EA, something wrong in it, I'll look at.
Regards,
Sergey
Dear Sergey,
Above is the source code for the client.mq4 and ImportNetEventsProcDLL.mqh that I am using.
Thanks a lot.
Dear Sergey,
Above is the source code for the client.mq4 and ImportNetEventsProcDLL.mqh that I am using.
Thanks a lot.
Hi amigo.
Here is EA that works as client, I tested - it sends and recieves.
Because now we have no any ticks(market is closed) I introduced Timer to call OnTick() function.
Please test and give me feedback.
Regards,
Sergey
Hi amigo.
Here is EA that works as client, I tested - it sends and recieves.
Because now we have no any ticks(market is closed) I introduced Timer to call OnTick() function.
Please test and give me feedback.
Regards,
Sergey
Dear Sergey,
Yes, it is working now. Thanks friend. You are awesome.
Hi amigo.
Here is EA that works as client, I tested - it sends and recieves.
Because now we have no any ticks(market is closed) I introduced Timer to call OnTick() function.
Please test and give me feedback.
Regards,
Sergey
Dear Sergey,
After tried your demo working. I am shifting my work to communicate between your metatrader4 (client) code with my custom C++ application (server).
My C++ application (server) is written in QT and the network module used is QT QTCPSocket and QTCPServer. (*fyi not your library)
The data transfer is successful from the metatrader 4 using your code to my C++ application.
However, the data transfer is not successful from my C++ application to the metatrader 4.
The metatrader4 code seems to not receive any data because the variable ps32_ReadLen display 0 while communicating with my C++ application.
Some of my observation:
At the metatrader 4 client execution, the ReadFromDouble return code is 0, and the ps32ReadLen[0] value is 0 as well. According to your material above, it means there is no data in the client stack with specified handle.
However,I have double checked my C++ TCP server whereby, another TCP client can receive the data.
Some of my test:
I test my C++ TCP server using a 3rd party software SocketTest v 3.0.0
When the SocketTest(client) send "HelloServer", the server will resend back "888999000" as shown above. So i assume the TCP server has no problem sending out messages.
I use the 3rd party software to simulate as TCP server and tries to send messages to the metatrader4 client.
But the variable ps32_ReadLen[0] value displays 0. This variable does display 1 when use your server.
The question I would like to ask is whether your metatrader 4 code can work with other C++ application.
If can, do you have any idea or any advise to me to solve the problem above?
Thanks.
Dear Sergey,
After tried your demo working. I am shifting my work to communicate between your metatrader4 (client) code with my custom C++ application (server).
My C++ application (server) is written in QT and the network module used is QT QTCPSocket and QTCPServer. (*fyi not your library)
The data transfer is successful from the metatrader 4 using your code to my C++ application.
However, the data transfer is not successful from my C++ application to the metatrader 4.
The metatrader4 code seems to not receive any data because the variable ps32_ReadLen display 0 while communicating with my C++ application.
Metatrader 4 ReadFromDouble Code:
Some of my observation:
At the metatrader 4 client execution, the ReadFromDouble return code is 0, and the ps32ReadLen[0] value is 0 as well. According to your material above, it means there is no data in the client stack with specified handle.
However,I have double checked my C++ TCP server whereby, another TCP client can receive the data.
The question I would like to ask is whether your metatrader 4 code can work with other C++ application.
If can, do you have any idea or any advise to me to solve the problem above?
Thanks.
DLL (Dynamic Link Library) functions is universal mean to exchange info between any programs independantly on lang in which they were developed.
One only thing is important - every lang has it's own rules to call DLL fuctions, that's all.
So if you use mine DLL interface you have no any problems.
DLL (Dynamic Link Library) functions is universal mean to exchange info between any programs independantly on lang in which they were developed.
One only thing is important - every lang has it's own rules to call DLL fuctions, that's all.
So if you use mine DLL interface you have no any problems.
I didnt use your DLL on C++ Server application.
I use your mqh in the metatrader 4 client .
Can it work this way?
I didnt use your DLL on C++ Server application.
I use your mqh in the metatrader 4 client .
Can it work this way?
Yes it can, but MT4 client must know your c++ server protocol, besides look at how MT4 DLL functions must be dtfined:
After connection is established your MT4 client should use this funtions for info exchange with your c++ server, something like that:
Yes it can, but MT4 client must know your c++ server protocol, besides look at how MT4 DLL functions must be dtfined:
After connection is established your MT4 client should use this funtions for info exchange with your c++ server, something like that:
I tested this java client/server.
Results are:
1. MT4 client can connect to it
2. MT4 client can send info to it and he recieves this info
2. MT4 client does't recieve info from this java client/server - the reason is my software is designed to send/recieve data blocks with variable length,
data block length is contained in the 4 bytes header, so MT4 client don't read it's data from stack until data length equal to number in 4 bytes header,
but in the case when java server send only character strings this number is very very very large !
So I should redo some things in my sofware for you to use it, or you should form data length four bytes header for every data block to send to MT4 terminal.
In other words MT4 client and it's software environment waits input data in format : DWORD, Data. DWORD - is 4 bytes header that comtains number of data itself + 4.