Can pipes be used across LAN computers?
In particular I'm looking for Windows, but if you have more info on other platforms, that will also help others who find this thread later.
Yes they can.
Named pipes can be used to provide
communication between processes on the
same computer or between processes on
different computers across a network.
If the server service is running, all
named pipes are accessible remotely
http://msdn.microsoft.com/en-us/library/aa365590.aspx
It should also be noted that a TCP/IP connection is effectively a pipe in the sense that you shove bytes in one end and they come out the other. TCP/IP connections are available on pretty much any platform you are likely to care about.
Related
I begin network programming with C++ in Windows OS. I know what is a Network protocol stack (like Educational Model of OSI and Operational Model of TCP/IP). Also, I know how a packet routed and switched in a network medium and many more other concepts about network programming and communication itself.
However, I know now when a process in Machine A wants to send a message to another process in machine B, the message must go through TCP/IP stack layers until it could be ready to put on physical media to reach the destination process in Machine B.
Packet should have the destination IP address of Machine B and also a Port Number. But I could not figure out the answer to the following questions:
Why we should specify a Port and how these 6000+ ports in operating systems (Windows) distinguished from each other?
How TCP/IP network protocol stack implemented in Windows OS? It is a driver or something else.
In Windows operating systems, every process has a TCP/IP protocol for itself or windows process uses the same TCP/IP protocol stack for them?
I know, these kinda questions are not too good for StackOverflow fans, but unfortunately, I couldn't find out the answer to these questions in the books or even via googling.
The port number is used to distinguish different applications running on the same machine from each other. Usually all (at least most) programs on the same machine will be communicating via the same IP address. The kernel needs to know what messages to dispatch to what program, the port number solves this problem. Each program will be communicating on a unique port, so when a message arrives for port x, the kernel knows what program to send the message to. Without the port number it would have to send the message to all programs and they would have to figure out if any given message was meant for them.
As for what books to read; I'd recommend "TCP/IP Illustrated, Volume 1 through 3" and UNIX Network Programming.
I search for some C++ ipc lib that allow me to simple switch between named pipes (local use) and tcp ip sockets so i can send messages outside computer.
My app have to parts. First is users space app second is service. I need to send short messages between them.
Platform Windows
I would recommend
Using RPC for IPC
RPC enables applications to call
functions remotely. Therefore, RPC
makes IPC as easy as calling a
function. RPC operates between
processes on a single computer or on
different computers on a network.
http://msdn.microsoft.com/en-us/library/aa365574(v=vs.85).aspx
and Best RPC Programming Practices :
http://msdn.microsoft.com/en-us/library/aa373563(v=vs.85).aspx
What platform are you targeting? While not with named pipes, but memory-mapped files, our MsgConnect seems to fit your needs. It was designed specifically for tasks like yours. MsgConnect lets you send messages with data payload on the local system (using memory-mapped files or TCP or UDP sockets) or across network (using TCP or UDP sockets).
With RCF C++ you can switch your transport layer (be it named pipes, tcp and udp with Boost:ASIO, etc) quite seamlessly.
I am currently working on creating a scalable server design in C++ for a ubuntu server. Is piping across a LAN achievable? What is the best option for speedy inter-LAN communication?
Background Info for those interested:
I'm making a multiplayer game with a friend. It's going to be TCP based. The thing is for linux making a server be multi client seems to mean creating a new process per client or select()ing through a fdset of connected clients. I want to combine these approaches and have a "manager" process that will select through maybe 100 clients and report any changes up the chain to a "taskmaster" process which will then distribute the change to the other manager processes. This will work fine with piping if the managers and taskmasters are on the same box, but if I want to scale it later I need a speedy inter-Lan communication method.
Checkout the netcat application. On one machine, you can run netcat as a server, piping the output to your process:
nc -l -p 1234 | myApp
This will listen on TCP port 1234, and print everything it receives out over stdout.
And on a second machine:
myApp | nc 192.168.1.2 1234
Where 192.168.1.2 is the IP address of the first machine. You'll need to look up the nc man page for the specific details - the above is all from memory.
A stream socket (SOCK_STREAM, combined with AF_UNIX if stricly local or AF_INET if over tcp/ip) is the network equivalent of a bidirectional pipe, with all data ordered.
Just the way you are asking that question, you seem to have the perception that for communication between related processes, pipes is the necessary answer.
The way to think about it is that you need communication between two processes, whether they be a couple of components in your system, client server pair, or whatever. Then you pick a mechanism that works for the given geography. Pipes work if the processes are local. You could also use shared memory queues for a no copy channel. You could also use IP (via sockets) over the loopback interface. To go across the network (WAN or LAN) you pretty much have to use IP.
Lastly, in addition to TCP, consider using UDP as well, because you get builtin message boundaries and easier endpoint management.
LANs typically are Ethernet based networks. This means that any protocol running on your network must be Ethernet based. TCP/IP can and does run on Ethernet networks but pipes and Local sockets are only designed to be an inter-process communication on a single host so is totally not suitable for multi-host applications.
If the various components run on different host, you will need to link them via some TCP/IP based protocol. There are some legacy protocols like IPX and UUCP that run over Ethernet but these have been totally superseded by TCP/IP.
I have one "server" process running, which will fetch data over the network for other processes running on the same machine as the server process.
How should I transfer data from the local server process and the local clients?
For retrieval of network data by the server process, Boost.Asio as suggested by #radman is a good choice.
Between server and local clients, Boost.Interprocess would be more efficient as this is interprocess data transfer, not requiring network usage.
Each of these Boost libraries provides a ready-to-run wrapper around complex underlying Win32 APIs, so you will likely get a working solution faster by using the libraries than by building your own special-purpose code with equivalent function.
You should check out Boost.Asio it fits your problem and is solid.
Standard TCP sockets work fine for interprocess communications between multiple processes on the same machine or different machines. It's standard, supported on almost all platforms and in almost all programming languages. You should be able to find sample C++ code easily.
To connect to a socket on the same machine, use "localhost" as its name or 127.0.0.1 as its IP.
I believe Windows has named pipes, which would work similarly to the suggestions in the other answers (especially #Irish's TCP sockets suggestion). See CreateNamedPipe() for details.
I want to have my applications communicate to each other. I think something like a server-client model would suit me well, but I was also wondering if there was a different way. I want this way to not involve those windows event hooks.
Note:
I am assuming you want to communicate with different processes on the same machine, although many of these concepts can apply across computers as well.
What you are looking for is IPC (Inter Process Communication).
You can do IPC via:
File
Signal
Socket
Message queue
Pipe
Named pipe
Semaphore
Shared memory
Message passing
memory-mapped file
My personal recommendation is a loopback connection via socket commands. It is difficult to give you much help beyond that without knowing more details about what you want to do.
You could loopback over Ethernet or use named pipes.
Look up Inter-process Communication (IPC) for a list of all related topics.
Edit: Given your comments about both being in different processes, then you are best off sending information across a network (ie sockets programming). This would give you the added advantage of being able to run the main process and the debug process on different machines. It's a bit hard to give you much information on it. You'll need to figure out what sort of requests you will send across the network and what sort of data you will send back in response. Effectively you need to design your own simple protocol.