Virtual Serial Port on linux through TCP [closed] - linux

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
With the Virtual Serial Ports Emulator I can
Create a virtual serial port connector
Choose a port e.g. COM35 for the connector
Create TCP-Server
Assign the previously created virtual serial port to the server
Then clients can establish a stream connection to the tcp server by knowing the ip address, tcp port and the name of the virtual serial port.
In the above example I created an MICRO_Test application (c++) that simply connects to virtual serial port. When I write data to this port it will be received by all clients.
You can see it in the log in the image above.
While this is on windows, is there a way to achieve some equivalent behaviour on linux machines?
To sum up:
Some binary code (as interface for e.g. webservices)
|
|
| [send/receive via virtual com port]
|
|
TCP Server & COM connector (multiple instances possible with different ports)
| | |
| | |
| | |
Client 1 Client 2 Client X
The clients read physical data from their real com ports and send the data through the tcp stream to the server.
For linux I read a lot about socat, tty and ser2net. However I cannot get a real clue how to achieve an architecture like above on linux? Can you help me out with some information?

In theory you could use Python with PySerial package. It can handle COM ports, RFC2217 (ser2net) and TCP raw connections (socat).
For example you would start socat on all clients with real hardware and connect to them via Python script.
This statement opens raw socket:
tcp_con = serial.serial_for_url('socket://<my_ip>:<my_port>')

Related

Port tunnelling from behind firewall to remote server via VNC'd laptop? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I have a command-line application on linux that uses a specific port to talk to a remote server. Unfortunately, at work, that port is blocked.
I am able to connect my laptop via VNC to the network, and the laptop is on a wifi connection that does have port access to the remote server. I am able to ssh to my laptop from the secure network when it is connected.
Is there a way of using ssh port tunnelling to work around this? Can I port tunnel to my laptop and have my laptop act as a middle-man between the firewalled network and the remote server?
Many thanks.
If I understood you correct you can call ssh from where you are to reach your laptop. Then you should be able to do something like this:
ssh -f -N -L <local port>:<remote server ip or hostname>:<remote server port> <laptop ip or hostname>
This will create start a tcp listening port on the host where ssh originates that forwards to your remote host and port via the machine you ssh to.
Excerpts from https://man.openbsd.org/ssh
-L [bind_address:]port:host:hostport
-L [bind_address:]port:remote_socket
-L local_socket:host:hostport
-L local_socket:remote_socket
Specifies that connections to the given TCP port or Unix socket on the local
(client) host are to be forwarded to the given host and port, or Unix
socket, on the remote side. This works by allocating a socket to listen to
either a TCP port on the local side, optionally bound to the specified
bind_address, or to a Unix socket. Whenever a connection is made to the
local port or socket, the connection is forwarded over the secure channel,
and a connection is made to either host port hostport, or the Unix socket
remote_socket, from the remote machine.
Port forwardings can also be specified in the configuration file. Only the
superuser can forward privileged ports. IPv6 addresses can be specified by
enclosing the address in square brackets.
By default, the local port is bound in accordance with the GatewayPorts
setting. However, an explicit bind_address may be used to bind the
connection to a specific address. The bind_address of “localhost” indicates
that the listening port be bound for local use only, while an empty address
or ‘*’ indicates that the port should be available from all interfaces.
-f
Requests ssh to go to background just before command execution. This is
useful if ssh is going to ask for passwords or passphrases, but the user
wants it in the background. This implies -n. The recommended way to start
X11 programs at a remote site is with something like ssh -f host xterm.
If the ExitOnForwardFailure configuration option is set to “yes”, then a
client started with -f will wait for all remote port forwards to be
successfully established before placing itself in the background.
-N
Do not execute a remote command. This is useful for just forwarding ports.

What exactly is a 'port', and how is it related to the internet? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 10 months ago.
Improve this question
I've searched extensively on this topic, yet I'm still confused about what exactly a 'port' is.
I know what it is 'conceptually', and I know that there are many different ports, and that some numbers, like 80 are reserved for certain uses, and I know that by typing in the 'netstat' commands in the CMD I can check if they are in use.
But I still don't understand what a port is. Does it 'physically' exist on my computer? Because all I see is one Ethernet connection line that I plug in, not some 6000 different ports that do different things.
And I don't really get how it's got to do with my internet browser. When I click on my 'Chrome.exe.' icon, does that 'open' the 80 -number port?
To reach a service on any networked computer you need to know 3 parameters. Some of them you provide explicitly and some of them are deduced by operating system implicitly. The three parameters are IP Address, Protocol, Port number. So any running service can be uniquely described by a combination of these three numbers.
Imagine, that we did not use port numbers. That would mean that on each computer we could have only one service using any of the protocols. So a web server could only serve HTTP protocol, mail server could only provide SMTP services and so on.
Usage of ports allows us to multiplex services on same computer. A port number is nothing more than a number, indicating what service should get a data packet. So we can have HTTP server, SMTP server and SSH server all running on a same computer and all using same protocol - namely TCP.
Also, these ports have nothing to do with a physical ports you see on your computer. Once again - they are just a number, allowing to distinguish which service (i.e. program) should receive which packet.
For example when I enter www.stackoverflow.com in my web-browsers address bar, my OS sends a HTTP request to {IP:104.16.34.249, Proto: TCP, Port: 80}. How does it know these numbers? IP address is resolved from the host name using the DNS protocol. Web browser is running HTTP protocol, which is using TCP. Port 80 is default port for HTTP. Behind the scenes, each packet will have destination address IP set to the above value and TCP payload will have destination port set to 80. On the SO computer, there will be a web-server running, which is listening for data received on port 80 and replies to my packet.
A port number is a 16-bit unsigned integer, thus ranging from 0 to 65535. For TCP, port number 0 is reserved and cannot be used, while for UDP, the source port is optional and a value of zero means no port.
A process associates its input or output channels via an Internet socket, which is a type of file descriptor, associated with a transport protocol, an IP address, and a port number. This is known as binding.
A socket is used by a process to send and receive data via the network. The operating system's networking software has the task of transmitting outgoing data from all application ports onto the network, and forwarding arriving network packets to processes by matching the packet's IP address and port number to a socket. For TCP, only one process may bind to a specific IP address and port combination.
Common application failures, sometimes called port conflicts, occur when multiple programs attempt to use the same port number on the same IP address with the same protocol.
https://en.wikipedia.org/wiki/Port_(computer_networking)
For short, ports are just logical numbers (not exists physically) related to services (or server software) whats are running above the operating system (ftp server, web server etc). When there is an incoming connection (or any traffic) addressed to a specific port, the OS can forward the traffic to the proper service for handling.
By default browsers are addressing the given site with port number 80 so
http://www.randomsite.com and http://www.randomsite.com:80 are identical.
If you request something from the internet then it has to send data to your request but the data is been sent in the form of data packets and the server needs some address to where it has to send the data packets and here comes the role of IP address.
An IP address identifies a machine in an IP network and is used to determine the destination of a data packet.
So the data will reach to your system or computer but still it doesn't know which application it has to send the data so here we use port number to identify the applications.
Port numbers identify a particular application or service on a system.

OpenJDK 7 AsynchronousServerSocketChannel only accepts localhost if bound to localhost/127.0.0.1 not external [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
> java -version
java version "1.7.0_09"
OpenJDK Runtime Environment (IcedTea7 2.3.3) (suse-3.16.1-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)
On openSUSE 12.2 (x86_64) and AppArmor is not running, and the firewall is disabled.
If server using AsynchronousServerSocketChannel is listening for connections and I specify localhost or 127.0.0.1, then it only accepts connections from the localhost and if I try to connect from another machine it rejects it. WTF?! If I instead put in the Java server its actual machine's hostname or IP address, rather than localhost or 127.0.0.1, then it does accept connections from elsewhere. Double WTF?!
There's no such issue when I use old-school synchronous server--it accepts connections from both the local machine and external ones when I have it bind to a localhost port. Moreover, I noticed the following difference between the synchronous and NIO2 when I had both set to bind to localhost:
> netstat -ltupn | grep
tcp 0 0 :::2340 :::* LISTEN 6749/java
tcp 0 0 127.0.0.1:12401 :::* LISTEN 6767/java
This is a big problem for me as I plan to deploy this server to multiple machines and it would be a major pain having to change the configuration files on every single one to add the actual hostname/IP rather than have localhost. What's the fix so it will work if I specify localhost as it should be?
I specify localhost or 127.0.0.1, then it only accepts connections from the localhost and if I try to connect from another machine it rejects it. WTF?!
That's exactly what it's supposed to do. You specified 127.0.0.1, which is the loopback interface, and which is invisible from external hosts.
If I instead put in the Java server its actual machine's hostname or IP address, rather than localhost or 127.0.0.1, then it does accept connections from elsewhere. Double WTF?!
Again that's exactly what's supposed to happen. I don't know why you're so surprised.
There's no such issue when I use old-school synchronous server--it accepts connections from both the local machine and external ones when I have it bind to a localhost port.
That's not so. Your observations are mistaken.
The correct solution in both cases is to bind to 0.0.0.0, or a null InetAddress, or omit the parameter, all of which have the same effect, of binding to INADDR_ANY, which means in this case to accept connections via any interface.
I suggest that that is what you were doing in the case that worked.

Serve multiple client request from server using bridge [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
My client basically make RDP kind of connection to server (see VNC server)
So, there are multiple client making connection to the server. To lower bandwidth, I want a bridge between server and clients. Basically this bridge will connect to server at a port and serve multiple client request.
I hope made my problem clear. Can anyone suggest what todo?
I want one connection from bridge to server and bridge should serve multiple client connection
For VNC there is a VNC reflector (bridge). You might be able to extend that to support RDP. I don't know of an existing RDP solution that is equivalent.
You can use ssh port forwarding to encrypt and compress traffic between your server and clients. For example, if you server runs on host server port 1234 and and bridge runs on host bridge, you set the tunnel up from host bridge like this:
[user#bridge ~]$ ssh -C -N -n -L *:1234:server:1234 server
So that when a client connects to bridge:1234 the connection is forwarded to server:1234 encrypting and compressing the traffic.

ports on computer and firewall and it's purpose - 101 question [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this question
Ok, computers have ports for applications to transfer data from the outside world into a firewall and then into a computer.
Then how does firefox and internet explorer use the same port on the same computer?
And why can't we use port 80 to pass all traffic from all places into the computer.
So why do we need specific ports?
It's not the ports on local that are important generally. It's the remote ports.
So when you open a browser and go to a site, you are establishing a connection from a (somewhat) random port on your end, to port 80 on the server end. The server responds back to you on the same connection. Web servers use TCP/IP, so this is what is called and established connection. If you were to go look at netstat -an on the server you connected to during web traffic, that is exactly what you would see:
tcp 0 0 ::ffff:192.168.1.223:22 ::ffff:192.168.1.230:2369 ESTABLISHED
That line says that my local machine has established a connection to my remote machine on port 22. My local machine picked a random outgoing port of 2369 to make this connection.
In this case, this is an ssh connection to my webserver in the basement.
Ports that servers should use for a particular service are listed here, but if you are going to control both ends of the connection, there is nothing stopping you from running a webserver on port 8383 if you wanted to. Just don't expect anyone else to get to it without you telling them about it. (or it being found in a port scan).
If you were running a webserver on your computer, it would open port 80 and listen for connections. Only one service can be LISTENing per IP address, so you couldn't run two web servers at once. Same thing if you then connected to your local webserver. You'd open a random local port and connect to your local port 80 on the same IP.
The opening the random local port is what allows you to have multiple local connections to a known remote port like 80.
There are 65536 ports available so it's unlikely you will ever run out, but many have 'well known' usages and are therefore avoided for your end of the connection. Generally everything above 1023 is fair game though. ( All services which require any kind of priviledge run on ports below 1023 )
This is a TCP/IP connection. TCP/IP has internal language to ensure the reliable delivery of information and does a handshake at the open of every connection to ensure the data can be transmitted.
Another common type of connection would be UDP. UDP does not establish a connection and is therefore a bit faster and has lower latency, but the programs that use it must be able to loose information and still work. It's basically a send off the data and pray protocol. Many online games work this way.
Each connection has a source and destination port. This is what allows you to have multiple connections from your machine to (say) a web server running on port 80. Connections are uniquely identified by SourceIP:SourcePort and DestIP:DestPort.
So in your example, Firefox and IE will be using the same port on the remote web server (port 80), but will have a different ports on your machine to tell them apart.
Try running netstat in a command prompt to see current connections.
ports can be used for anything, but there are conventions of the protocols to expect on certain ports.
and you can use 80 for other functions, some people do that as a simple way of bypassing firewalls...
however, only 1 application can be listening on a port.
Some netstat output can show you what's going on:
C:\Temp> netstat -an
TCP 192.168.XXX.150:1493 74.125.45.100:80 ESTABLISHED
TCP 192.168.XXX.150:1504 69.59.196.213:80 ESTABLISHED
TCP 192.168.XXX.150:1507 74.125.91.138:80 ESTABLISHED
TCP 192.168.XXX.150:1510 65.55.11.162:80 ESTABLISHED
TCP 192.168.XXX.150:1518 69.59.196.211:80 ESTABLISHED
TCP 192.168.XXX.150:1519 69.59.196.216:80 ESTABLISHED
TCP 192.168.XXX.150:3711 64.208.186.96:80 CLOSE_WAIT
Note that the 192.168.XXX.150 address is my computer's address on my home network. The 4 digit numbers following the IP address are the local port my computer is using to communicate with port 80 on a bunch of different servers.

Resources