Can I use ZeroMQ with UNIX sockets in the same thread in C++? - c++

I am trying to use ZeroMQ to connect to a historical data server written in Python while I connect to Interactive Brokers' Trader Workstation (TWS) using C++ through UNIX socket in Linux. But I can't seem to get both to work at the same time. I tried to connect to the Python server using ZeroMQ first, and then to TWS once the connection is established. But after I connect to TWS, I can't seem to interact with my original ZeroMQ connection in any way. The connection with TWS would always lose whenever I provide the ZeroMQ socket to call zmq::poll. But if I don't include the ZeroMQ socket, zmq::poll works just fine with the file descriptor from the connection to TWS. I am not too experienced with either UNIX sockets or ZeroMQ, but is it true that I can't use ZeroMQ and sockets API in the same thread? I thought it would be simple to add ZeroMQ to the original Interactive Brokers socket client, but it is more complicated than I expected. Any suggestions would be greatly appreciated.

Related

Connecting non-IOCP client with IOCP Server

I am designing a client-server application.
My server will be in C++ and using IOCP for TCP/IP communication.
Decision for technology for client development not decided yet. So I have few questions regarding IOCP compatibility with client to be developed in future (I need to freeze design for Server):
Can I use general socket programming of java(client will be developed in java more likely) to communicate IOCP based Server?
How IOCP responds for abrupt and graceful termination of client connection (what notification I'll get on server)?
Thanks
Nipun
You are talking about socket programming here, and the middle layer is TCP/IP and so the network programming library (e.g. IOCP) is irrelevant. You can use whatever language or library on the client side.
For first question,yes you can use any language as long as you use TCP/IP protocol.
For second question,my solution is,create an stop event for iocp,and every once a while,send a little package to client,if client does not reply this package,set the stop event up,and release the connection for the client

Socket communication between c++ Client and node.js Server

I want to make my c++ app (running on Linux system) to connect and send data to node.server via socket.
I tried to implement small sample app by using socket.io library (https://github.com/uning/socket.io-client-cpp), but doesnt helping me to achieve my goal.
Any guidance on this or alternative to do something like this.

C++ socket design

I am designing a client server socket program using TCP/IP.
The server listens on a certain port, the client program makes 2 connections to the server. One is for command and response and the other is for streaming of data.
For the command and response, I can use the normal blocking socket mode to receive the client command and send the server response.
For the streaming data, the server would wait for the client to send a start stream command and begins continuous sending of data to that client. The issue now is I need the handler to also listen on this connection for the stop stream command. Hence, I was thinking of making this connection non-blocking so that the receive would not block followed by a non-blocking send.
Is this method of implementing the server and client handler efficient?
Take a look at Boost::asio socket management layer. It's very well written.
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/tutorial/tutdaytime1.html
Yes it is very efficient.
You can use libraries like libevent.
From perspective of efficiency, the server should always be designed to use non-blocking sockets, and use event-driven asynchronous I/O architecture. Blocking sockets should be avoided at server side.
Fortunately, there've been a few mature open source frameworks you can use. Among them, libev is most lightweight.

C++ & Boost: I'm trying to find an example TCP program with a server that accepts connections from multiple clients

A chat program would be a good enough example.
Just need a server that can accept multiple connections from the clients, and the server needs to be able to send messages to individual clients.
I plan to turn this into a distributed computing program to work with multiple Neural Networks.
Asio is the Boost library that handles networking. There's a chat server example listed here.
I cannot give you an example progam. But to write a server things that you have to do:
1. server will listen at a port for connection
2. thread pool which will accept the connection and serve request
3. write the server code in thread safe manner
You have to use socket programming A good link for that http://beej.us/guide/bgnet/
you can use win32 api in windows and posix for linux

Communicating over telnet

I can't use Boost ASIO (reasons not related to programming) and I looked around and libcurl looks good. I'm building the binaries at the moment and decided to get some feedback from the community.
Any comments regarding libcurl/alternatives?
UPDATE:
libcurl's not great for telnet. It's 2010! Shouldn't there be a simple way to do this? Winsock?
Telnet is a very simple protocol. Some wonky stuff to negotiate the terminal type but I'm sure your robot doesn't care where the cursor ends up. Just use a socket to open a TCP/IP connection on port 23 and send the command strings, terminated with a '\n'.
RFC854 is referring to it as a protocol, so perhaps it is one.
When I think of telnet I think of connecting to port 23 on a VT100 to get a terminal window to a remote UNIX host. You can also use telnet to other ports to get a TCP/IP connection which we used to use years ago on MUD/Talker servers, but this is simply a regular TCP/IP connection that is used in a connection-based client-server application. Actually "connectionless" is a misnomer as you do connect to the remote server, just in the connectionless model you do not retain the connection throughout the session, whereas in a connection-based model, the session begins when the client connects and ends when it disconnects.