I am new to quickfix (I'm a student trying to teach myself), and have downloaded the examples from quickfix.org (in c++) and have been able to connect ordermatch to tradeclient and get them talking to each other. I changed the config file for ordermatch to allow multiple clients and got that working (ordermatch can receive orders from multiple clients and manage the order book).
I have been trying to find a way to alter ordermatch to send it's confirm messages to ALL clients, not just the sender.
I have a seperate implementation of a limit orderbook and want to crack the incoming messages (orders, cancels, etc) and store them in my limit orderbook. My orderbook watches the book an makes trading decisions based on it. The problem is, I can't figure out how to get ordermatch to send all updates to this client. Further, I am having a hard time figuring out how to "soup up" the tradeclient to not only send orders, but receive and crack them.
I'm thinking I need to have an acceptor and an initator in each application(in ordermatch and in one of the tradeclients)--I've read this is possible and common but can't find any sample code. Am I on the right track here, or is there a better way to set this up? Does anybody have some sample code they can share? I am not planning on using this for live trading so crude code is perfectly fine by me.
Thanks in advance
Brandon
Same application can act as Initiator for one session and Acceptor for different session.
Infact you can have multiple Acceptor/Initiator sessions from same application.
Config file needs to define multiple sessions.
Or you can have separate config file for each session.
If I understand correctly, I think what you're trying to do is intercept messages between an OMS and a broker (c.f. client and server) and act depending on what they contain. There are a few ways you could do this, including intercepting at the TCP layer, but I think that the easiest way might be to use 2 separate programs as #DumbCoder suggests and connect to one of them as an acceptor from your clients, process the messages and then pass them on to another program via another protocol and then send them on from the other program. Theoretically you can create another instance of the engine in your program and, by using different config files on creation (when FIX::FileStoreFactory storeFactory(*settings); is called) of each instance of the engine. However, I have never seen this done and so feel that it could cause problems. If you do try this method I would strongly advise putting the initiator and the connector in different dlls which might just separate the two engine instances enough.
Related
I have written a c++ app on Windows that uses a secondary thread to communicate with a PLC. The content of the messages are vectors (of fixed size around 120) of uint_16t. The interface also allows to send something to the PLC.
I am really new to this so I want to start correctly. I would like now to separate the communication from the app and run it in a separate process. One reason for that is that I would like to write other apps that could also use this process for communicating with the PLC. The communicating process would thus organise and distribute the messages, since all app don't share the same messages from or to the PLC. So I still need to receive the vector of uint_16t (and for that I need to let know to the communicating process which one to read!) but also to send some things to the PLC. Thus I would need a bidirectional communication.
I have seen that there are many possibilities to achieve this but I would like to communicate via Message Queues (Message Passing). If possible, I would also like to allow apps on other computers to connect to this communicating process.
I am therefore looking for a c++ library to do that. I would appreciate any advises about which one to favor.
I can use message queue from Boost but it doesn't allow to communicate with another computer.
As a secondary question related to this one, I would like to start the communicating process if at least one interface process is opened. How to achieve that synchronization?
I thank you in advance for your help.
I'm new to c++ and I started to code my server with boost. I follow a lot of example on the web and on the official doc. But i found nothing (maybe I don't ask the good question) about this-> communicate with a specific client. By this I mean that->
old question:
Server launch and wait for connection-> client(1) connect through
TCP-> server accept client and start async_read
Let's say 3 clients also connect->
How I'll tell to my server too write too client(2) or (3) but not
both?
I express myself badly
New question:
My server work fine, when client send data to server (custom client in Unreal engine 4) he can read it then write back to my client with no problem. I search a way to speak to the client I want without needed him to send data. Example:
client 1 write to server-> the data send to server launch the next action-> write to a specific client.
More specific example:
Client 1 want to send request to client 10, so client 1 write to the server the action «action, id client» (request, 10) then the server know that he need to talk to the client 10 and send request.
My problem is not on the client side, but on the server side.
I'm sure it's pretty easy and I just don't understand some basic stuff, if someone could provide me a direction, an example or simply an explanation it would be appreciated. Thanks for future answer.
EDIT:
If somebody have hard time like me (I know it's easy but we never know :p, maybe it could help someone) here the answer.
I include this inside the file where I use to connect, write, send, etc.
std::map<int, tcp::socket> playerRemote;
I set it->
playerRemote.insert(std::pair<int, tcp::socket>(id, std::move(socket_)));
use the socket->
boost::asio::async_read(playerRemote.at(id_to_use)
Question resolve! thanks for help!
Every time that your server program did an accept it got a new socket with a new client on the other end of it.
The usual practice is to have some kind of object which you create and initialize with this new socket. And then you put that object into some kind of structure. Like a set, a map, a vector, a list, anything really.
When you want a particular client then search that data structure for it. If you used a map or a unordered_map then you can get it quickly by whatever key you used.
Now you have your client object you can call a method on it. Like your own version of "send" which can add it to a per-client buffer. Since message sending is asynchronous in Boost ASIO (it's right there in the name) you know you may not be able to send it right away.
The Boost ASIO chat example application is good about this.
Look at the link that The Quantum Physicist put in comments. Especially this one: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp11/chat/chat_server.cpp
I'm right now I have a Thrift TSimpleServer that is going to accept connection from multiple clients at once. Once those clients connect they will be sending data that is to be stored in a respective file on the server. Now I'm pretty new to thrift so I'm not sure how the TSimpleServer handles multiple connections(haven't tested that yet) anyways I'm not even sure how to go about saving the received data in separate files simultaneously. I assume a separate thread is created to handle each client connections but how do give each thread a file path to use?
TSimpleServer handles simply :-) one connection at a time. You may want to use TThreadedServer or TThreadPoolServer which are able to process requests in parallel.
How you do give each thread a file depends on your exact use case. For example, you could consider deriving an own version of a thread factory and register this one with the thread Manager. Although the following blog post does not exactly cover your scenario, you should get the idea from the code at the end of the text:
http://mikecvet.wordpress.com/2010/05/13/apache-thrift-tutorial-the-sequel/
My situation: I would like to create a hobby project for improving my C++ involving real-time/latency programming.
I have decided I will write a small Java program which will send lots of random stock prices to a client, where the client will be written in C++ and accept all the prices.
I do not want the C++ client to have to poll/have a while loop which continuously checks for data even if there is none.
What options do I have for this? If it's easier to accomplish having a C++ server then that is not a problem.
I presume for starters I will have to use the boost ASIO package for networking?
I will be doing this on windows 7.
Why not just have the Java server accept connections and then wait for some duration of time. e.g. 10 seconds. Within that time if data becomes available, send it and close the connection.
Then the C++ client can have a thread which opens a connection whenever the previous one has completed.
That should give quite low latency without creating connections very often when there is no new data.
This is basically the Comet web programming model, which is used for many applications.
Think about how a web server receives data. When a URL is accessed the data is pushed to the server. The server need not poll the client (or indeed know anything about the client other than its a service pushing bytes towards it).
You could use a Java servlet to accept the data over HTTP and write the code in this fashion. Similarly, boost::asio has a server example that should get you started. Under the hood, you could enable persistent HTTP so that the connections aren't opened / closed frequently. This'll make the coding model much simpler.
I do not want the C++ client to have to poll/have a while loop which
continuously checks for data
Someone HAS to.
Need not be you. I've never used boost ASIO, but it might provide a callback registration. If yes, then just register a callback function of yours with boost, boost would do the waiting and give you a call back when it gets some data.
Other option is of course that you use some functions which are synchronous. Like (not a real function) Socket.read() which blocks the thread until there is data in the socket or it's closed. But in this case you're dedicating a thread of your own.
--edit--
Abt the communication itself. Just pick any IPC mechanism (sockets/pipes/files/...), someone already described one I think. Once you send the data, the data itself is "encoded" and "decoded" by you, so you can create your own protocol. E.g. "%%<STOCK_NAME>=<STOCK_PRICE>##" where "%%", = and ## (markers to mark start, mid and end) that you add on sender side and remove on receiver side to get stock name and price.
You can develop the protocol further based on your needs. Like you can also send buy/sell recommendation or, text alert msgs with major stock exchange news. As long as your client and server understand how the data is "encoded" you're good.
Finally, if you want to secure teh communication (and say you're not using some secure layer (SSL)) then you can encrypt the data. But that's a different chapter. :)
HTH
I've already developed some online games (like chess, checkers, risk clone) using server side programming (PHP and C++) and Flash (for the GUI). Now, I'd like to develop some kind of game portal (like www.mytopia.com). In order to do so, I must decide what is a good way to structure my server logic.
At first I thought in programming separated game servers for each game. In this way, each game will be an isolated program that opens a specific port to the client. I thought also in creating different servers to each game room (each game room allow 100 clients connected on the same time). Of course I'd use database to link everything (like highscores, etc).
Then, I guess it is not the best way to structure a game portal server. I'm reading about thread programming and I think that is the best way to do it. So, I thought in doing something like a connection thread that will listen only to new connection clients (that way every type of game client will connect in only one port), validate this client (login) and then tranfer this client to the specific game thread (like chess thread, checkers thread, etc). I'll be using select (or variants) to handle the asynchronous clients (I guess the "one thread per client" is not suited this time). This structure seems to be the best but how do I make the communication between threads? I've read about race conditions and global scope variables, so one solution is to have a global clients array (vector or map) that need to be locked by connection thread or game thread everytime it is changed (new connection, logout, change states, etc). Is it right?
Has anyone worked in anything like this? Any recommendations?
Thanks very much
A portal needs to be robust, scalable and extensible so that you can cope with larger audiences, more games/servers being added, etc. A good place to start is to look into the way MMOs and distributed systems are designed. This might help too: http://onlinegametechniques.blogspot.com/
Personally, I'd centralise the users by having an authentication server, then a separate game server for each game that validates users against the authentication server.
If you use threads you might have an easier time sharing data but you'll have to be more careful about security for exactly the same reason. That of course doesn't address MT issues in general.
TBH I've been doing a voip system where the server can send out many streams and the client can listen to many streams. The best architecture I've come up with so far is just to bind to a single port and use sendto and recvfrom to handle communications. If i receive a valid connect packet from a client on a new address then I add the client to an internal list and begin sending audio data to them. The packet receive and response management (RRM) all happens in one thread. The audio, as it becomes ready, then gets sent to all the clients from the audio thread. The clients respond saying they received the audio and that gets handle on the RRM thread. If the client fails to respond for longer than 30 seconds then I send a disconnect and remove the client from my internal list. I don't need to be particularly fault tolerant.
As for how to do this in a games situation my main thought was to send a set of impulse vectors (the current one and 'n' previous ones). This way if the client moves out of sync it can check how out of sync it is by checking the last few impulses it should have received for a given object. If it doesn't correspond to what its got then it can either correct or if it is too far out of sync it can ask for a game state reset. The idea being to try and avoid doig a full game state reset as it is going to be quite an expensive thing to do.
Obviously each packet would be hashed so the client can check the validity of incoming packets but it also allows for the client to ignore an invalid packet and still get the info it needs in the next update and thus helping prevent the state reset.
On top of that its worth doing things like keeping an eye on where the client is. There is no point in sending updates to a client when the client is looking in the other direction or there is something in the way (ie the client can't see the object its being told about). This also limits the effectiveness of a wallhack packet sniffing the incoming packets. Obviously you have to start sending things a tad before the object becomes visible, however, or you will get things popping into existence at inconvenient moments.
Anyway ... thats just some random thoughts. I have to add that I've never actually written a multiplayer engine for a game so I hope my musings help ya a bit :)