Problem with calling socket communication functions via DLL

 

Hello,


I've build a Server implementing some neuro-network functions and i want to communicate from an EA with this server.

To do so, I implemented some socket-communication functions as an DLL but I got the following problem:


- when calling the connect - function of WinSock via the DLL I always get an error 10049 which means "illegal address " but my

server is running (localhost, Port 4711) and acccessable (tested with telnet).


Does anybody know if socket-communication is possible(allowed out of an EA or what else is going wrong ?


Juergen

 
EA can call DLL that uses socket functions. Check your DLL.
 

Hello Juergen,

can I see your source code? I need to implement socket functions in a DLL as well and definitely need some sort of starting template..

Best Regards,

Alex

 
JStein:

[...]

- when calling the connect - function of WinSock via the DLL I always get an error 10049 which means "illegal address " but my

server is running (localhost, Port 4711) and acccessable (tested with telnet).

Does anybody know if socket-communication is possible(allowed out of an EA or what else is going wrong ?

I'd be hugely surprised if it wasn't possible to do socket communication from a DLL which is being called by an EA. There's no reason why it shouldn't work, and both MetaTrader itself and various external libraries are reliant on socket communication, albeit usually indirectly, for doing things such as email and HTTP.


However, you're probably going to have far more success pursuing this question on a forum devoted to C++ and Winsock, rather than on this forum which is almost exclusively about MQL and has very few members with the expertise you need.


To start you off, the most likely reason for 10049 is that you're not build the sockaddr properly for the call to connect(). You need to be populating it along something like the following lines:


DWORD Port = whatever, IPAddress = whatever;

sockaddr_in address;

address.sin_family = AF_INET;

address.sin_port = htons(LOWORD(Port));

*(LPDWORD)&address.sin_addr = IPAddress;


 

Thanks a lot,


it was my fault (programming error, I fixed it already.

 
JStein wrote >>

Thanks a lot,

it was my fault (programming error, I fixed it already.

I am sending send signals from a central server running MT4 to other MT4 running in other PCs across a network. Do you mind sharing your source code how to initiate socket connection? My email is williamwongys@yahoo.com, thanks.

 
  1. Ensure that the functions you are calling from the DLL have the correct signatures (parameter types, return types, calling conventions, etc.). Mismatched function signatures can lead to runtime errors or unexpected behavior.

  2. Verify Function Exporting: Make sure that the functions you intend to call are properly exported from the DLL. You can use tools like Dependency Walker or dumpbin to inspect the exported symbols of the DLL.

  3. Load the DLL: Ensure that you are loading the DLL correctly in your application. You can use functions like LoadLibrary (for Windows) or dlopen (for Unix-like systems) to load the DLL dynamically.

  4. Resolve Symbol Addresses: After loading the DLL, obtain the addresses of the functions you intend to call using functions like GetProcAddress (for Windows) or dlsym (for Unix-like systems). Ensure that the function pointers obtained are valid.

  5. Check Socket Initialization: If your socket communication functions require socket initialization (such as calling WSAStartup on Windows), make sure that you initialize and clean up sockets properly in your application.

  6. Handle Errors: Check for error conditions after calling socket functions and handle them appropriately. Functions like WSAGetLastError (for Windows) or errno (for Unix-like systems) can help you retrieve error information.