Virtual COM port to Socket communication - c++

I have a virtual COM port and socket in my app , i want to transfer data from this Virtual COM port to a socket and vice versa.
How can i do this?
Is there some sample code or good library out there to do so? Eventually this should work on Windows CE, but initially it should work on regular Windows.

It depends what you need the service to do.
Is it bi-directional, does opening the port have to automatically setup a new network link, do you need to set serial port parameters over the network?
If you only really need to remote a serial port and don't need any command and control data then most introductions to network programming start with some sort of chat server where everything typed at the client end goes to the server as text - it should be trivial to modify this so that the source text comes from a serial port

Related

Checking if a program is running on local network

I want to write a simple program in c++ that use tcp socket to communicate with the same program on another computer in lan.
To create the tcp socket I could make the user write the ip and the port to make the connection. But I also need to be able to autodetect in the local area network if there is any computer also running the program.
My idea was:
when the program is autodetecting for available connection in lan, it will send all ips a message via udp to a specific port, meanwhile it will also keep listening to a port waiting to eventual answer.
when the program on the other computer is opened for lan connection, it will keep listening to the a port in case another computer is trying to detect, then it will send also via udp the response messagee notifying the possibility of connection.
All the security system is another problem for which I don't need answer now.
// Client 1:
// Search for all ips in local network
// create udp socket
// send check message
// thread function listening for answers
// if device found than show to menu
// continue searching process
// Client 2 (host) :
// user enable lan connection
// create udp socket
// thread function listening for detection requests
// if request structure is right send back identification message
// continue listening for request
My question - Is there a more efficient or standard way to do something like that?
Testing whether another computer is listening on a given port is what hackers do all day to try to take over the world...
When writing a software like you describe, though, you want to specify the IP and port information. A reason to search and automatically find a device would be if you are implementing a printer, for example. In that case, as suggested by Hero, you could use broadcasting. However, in that case, you use UDP (because TCP does not support that feature).
The software on one side must have a server, which in TCP parlance means a listen() call followed by an accept() until a connection materialized.
The client on the other side can then attempt a connect(). If the connect works, then the software on the other side is up and running.
If you need both to be able to attempt a connection, then both must implement the client and server (which is doable if you use ppoll() [or the old select()] you know which event is happening and can act on it, no need for threads or fork()).
On my end, I wrote the eventdispatcher library to do all those things under the hood. I also want many computers to communicate between each others, so I have a form of RPC service I call communicatord. This service is at the same time a client and a server. It listens on a port and tries to connect to other systems. If the other system has a lower IP address, it is considered a server. Otherwise, it is viewed as a client and I disconnect after sending a GOSSIP message. That way the client (larger IP address) can in turn connect to the server. This communicator service allows all my other services to communicate without having to re-implement the communication layer between computer over and over again.

C++ terminal server for existing terminal client protocol

I want to communicate with a C++ simulated UART which is communicating with a (simulated) guest Linux system terminal.
What I have is a callback called when receiving character outputs from the UART, and a method I can call to send characters to this same UART.
I'd like to be able to connect to this UART with my host terminal, implementing a server socket communicating using an existing protocol.
What protocol should I use to keep a high compatibility? I'm thinking about telnet. Are there existing frameworks in C++ or C to implement that quick and easy?

Sniff LPT Traffic in windows

I need to programmatically sniff data that is being passed through the parallel port (LPT) to printer in Windows XP.
This is what I have tried in the past 3-4 days:
Firstly, I tried to read data using windows CreateFile(), WaitCommEvent() and ReadFile() functions. But they seem to block the port, so that the port access is denied to other applications.
Secondly, I have used com0com to create virtual COM port to get the printer data and then send it to LPT. This requires me to make the source user space application send the data to COM port first and then I write my code to tunnel that data to printer through LPT port. So, I basically redirect the print stream through COM port rather than sniffing it over the LPT port. So, it requires changing the settings in the application whose print data I need to capture. Hence, this is more of a hack but not something I need.
Finally, I have used PortMon and PrintFil as mentioned in this question. They work fine but I need to include PortMon's sniff functionality in my application.
So, is there any open source library or code sample which could be used to sniff the parallel port data similar to what portmon or printfil do ?

iPhone/iPad wifi tcpip connection to other computers on a wifi

I have multiple computers on a Wifi router. For the iPhone/iPad In objective-c how can I determine what computer is on what tcpip socket address so I can choose and connect to that computer? (each computer is a socket server written in c++ and I need to be able to easily check the status that is out putted)
If your computers are all Macs, it is pretty easy. Simply use the NSNetservice class to advertise the service and the socket port that you already have.
Then, on the iOS devices, simply use a NSNetServiceBrowser object to look for your particular service by name, and connect to one or all of them as required.
If your computers are not Macs, you can look into Bonjour for Windows, or any Zeroconf implementation such as Avahi on Linux.
TCP programming

How to acess COM port of remote system?

I Want to access the COM port present in the remote system from system. Any help would be appreciable.
I am using windows XP in both remote as well as local system.
The com0com project, and especially the com2tcp application should help you.
In conjunction with the Null-modem
emulator (com0com) the com2tcp enables
to use a COM port based applications
to communicate with the TCP/IP based
applications. It also allows
communication with a remote serial
port via the TCP/IP.
Personally, I use SerProxy, which makes that com port looks like telnet:
Serproxy is a multi-threaded proxy program for redirecting network socket connections to/from serial links, in cases where the remote end of the serial link doesn't have a TCP/IP stack (eg an embedded or microcontroller system). The proxy allows other hosts on the network to communicate with the system on the remote end of the serial link.
I also looked into com0com before, but I finally decide not to use it, as it requires a driver installation. Where as serproxy just need to be run. Another nice part is that if the com port is not being "used" remotely, I can still access it locally.
I've used Advanced Virtual COM Port to share a COM port remotely.
On the local PC, it creates a virtual COM port that mirrors the activity of a real COM port on the remote PC. The remote PC can be on a local network or on the Internet. (If on the Internet, you just have to make sure your firewalls allow the particular TCP ports through.)
I tried several programs to share a COM port remotely, but this was the only one I found that also shared the serial hardware handshaking signals. So we picked this one, and it worked great. We used it about 3 years ago, to access a Japanese CDMA modem dev board, sitting in Japan, from Australia.