Connecting non-IOCP client with IOCP Server - c++

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

Related

C++ SFML UDP Socket receiving and sending data to multiple clients

I am trying to learn network socket programming basics and I can't understand some things. I have assignment to create working MMORPG server-client application where even up to 1000 clients can be connected at same time to server using SFML library. I started with some simple stuff like testing packets, sockets and making simple applications like chat in console and multiplayer tic-tac-toe for other assignment. I heard that using UDP sockets is way to go for real-time applications like games so I am trying to understand how does it work. In TCP Socket I am simply listening to connections, once client connects I can assign him to certain socket and keep listening for connections while I send data and identify him.
I don't know how to identify clients using UDP socket. I am not even sure if my approach is right.
I thought that it should work like this:
1.I create UDP socket binding it to certain port.
2.I am making sure that client got permission to receive data from server.
3.In loop I am receiving and sending packets from/to every client.
4.If client get disconnected, we close connection for him/delete him from vector of clients.
So how I do this with UDP sockets? Are they necessary for this kind of architecture ? Also I would appreciate any good article about making working client-server application with good protection and performance. Thanks in advance :)
Okay so I found actually two good articles about using UDP sockets and overall network in game:
SFML Game Development by Example: https://www.packtpub.com/game-development/sfml-game-development-example
Author is writing 3 SFML games in C++ and explains everything as he goes, using UDP sockets and taking care of packet reliability included.
Gaffer on Games article: http://gafferongames.com/networking-for-game-programmers/
Big amount of informations about game networking.
I hope that it helps for someone looking for clues about UDP sockets and examples of using it in network game development.

Can I use ZeroMQ with UNIX sockets in the same thread in 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.

IPC between FastCGI C++ / Nginx and C++ Application

I'm trying to create a Gateway which offers a RESTful interface to send/receive messages to Devices which communicate over Bluetooth Low Energy (BLE). Basically it translates GATT to HTTP and vice versa.
The basic architecture looks as follows:
A BLE Dongle is connected to a Linux computer (f.e. Raspberry Pi) a C-Program opens a serial connection to the BLE Dongle to send/receive/process messages. It receives requests from a C++ Application over IPC using a TCP/IP Socket and also uses this socket to forward replies from BLE Devices (f.e. Sensors) to the C++ Application (which acts as a multithreaded server for each connected BLE Dongle).
The C++ Application saves this information (f.e. discovered devices, connected devices and their data) and also implements an interface to control basic Bluetooth Low Energy functions like Discovery,Connect.. etc.
A client can send HTTP Requests (GET/POST) to a Nginx Webserver which uses FastCGI. I would like to parse the requests in this FastCGI Application and then communicate with the C++ Application to execute the commands
f.e. Client opens an URI xyz/discover sending a GET Request. The FastCGI Application parses this requests and calls the Discover function of the C++ Application to start a Bluetooth Low Energy discovery.
My Question is how to best communicate between the C++ Application and the FastCGI C++ Application.
My Ideas:
The C++ App forks a new child which does exec fcgi-spawn (path to my fcgi app as an argument). Then create two pipes for full-duplex communication between parent and child
Using named Pipes between both processes
Is it a good idea to just integrate the FastCGI functionality in my C++ Application? The C++ App runs several Threads: one to accept new TCP connections in case a new Dongle is connected. It starts a Thread for each new Dongle. Could I just create another thread which is responsible for parsing FastCGI Requests?
Since I never really worked with FastCGI and nginx I'm just learning as I go. So I would be grateful for some input. Thanks!

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