I need to be able to communicate with a component on an Android 8 device on a specific port on the device. One way communication is fine because I either reverse-forward a connection and listen on the host or forward a connection and input on the host.
Is there a simple solution to two-way communication? I would like to avoid having to swap the direction of the connection on each exchange.
Seems that I misunderstood the way adb forward and adb reverse work. The are not one way channels, but two way. The difference is that adb forward connects to a port on the device and binds to a port on the host, and adb reverse does the opposite.
Related
Please forgive me for being naive on the subject, however, I do not understand ports and how they work in the slightest. I am trying to make a program where two computers could communicate given their IP addresses and I am using TCP protocol. I don't, however, know what port(s) I would be able to use for this application, because when I look up TCP ports I get a list of ports each with their own function. Any help is useful.
P.S. I am using C to create my program
The short answer is you can choose any port you like - although the safe range is generally considered to be between 1024 and 65535. The only problem that you will encounter is when some other program installed on the device is already listening on that port. Unfortunately, there is no port that is guaranteed to be available to listen on.
One possible solution to this is to have a primary listening port and a fallback secondary port. You can then first try to connect on the primary port and, if a satisfactory response is not received, try to connect on the secondary port. However, even this is not infallible, as there is a chance that the secondary post could also be in use.
The easiest approach is to try to create your listener on the port that you have chosen, and if the port fails to create, let the user know that some other application is preventing execution of your application.
I have a windows application on my PC which connects to a device over telnet. It sends a series of commands to the device, and the device responds to it.
Is there any way I can listen to what that program is writing to the device?
I tried using win32 socket programming to create a client that connects to the application. But, I get an error saying connection refused. When I analyze the traffic between the application and device on wireshark, I can see that the application uses different ports each time it reads from or writes to the telnet port(23) of the device.
Is there any way I can read the commands sent by the program to the device?
If you want to capture program's output to the device
programmatically, the right way is not to connect to the program (you
can't tap into an existing connection), but instead provide a server
that will stand for target device from the program's point of view.
It's going to work if the program can be configured to connect to the
device at different address and port. Write a "proxy" that listens on
some fixed port, and for any accepted connection, opens a client
connection to the real device. Then it should forward data in both
directions between the accepted connection from the program and the
client connection to the device. During this, you can also parse data
or do whatever you want with them, e.g. forward them to yet another
connection to another real device.
I am writing a simple sender and receiver program to transit using UDP so it's connectionless, but I am having a problem figuring out whether my receiver program needs to call bind() or the server and/or both. My receiver program(client) will sit in an infinite loop waiting to receive data from the sender(server) and then it will print out the data. I'm not quite sure what bind() does exactly besides associating an address/port with a specific socket. Why is it that I need to call bind()?
You need to call bind(2) so that the OS knows which application to route network packets to. When you call bind with a specific port for a given protocol (e.g. TCP or UDP), you're asking it "whenever you see a network packet on port XXXXX, please give it to me".
Say, for example, that two copies of your program were running, and they both wanted to listen for UDP packets on the same port. If they both call bind on the same port, then one will succeed and one will fail, since the OS can arbitrate who is bound to each port. Then, any packet received on that port will be given to whichever instance of the program succeeded at binding to that port.
when you want to make a socket a fixed address or/and port, you use bind.
See you when developing a Network Application you need to specify "Address and Port" to Bind because if you want to set it for Localhost your application is not able to communicate with the all over the network its only for your system which its communicating.. If you set it with your Network address it's not able to communicate as localhost Its only communicate with the network and If you set it to 0 then It can be use as both for localhost and Network.
i am writing a tcp server code to monitor tcp/ip traffic coming to my system.
Can anyone have the idea about how to bind to different tcp ports,instead of a single port.
or can anyone ve the idea about how to do it?
expecting ideas from alll good hearts
Take a look at libpcap, it's closer to what it sounds like you need.
For each port you are listening on you need to prepare the data structures required to bind to that port and listen on it. You cannot listen on ALL ports -- unless you work at driver level and intercept the packets before they are dispatched to the application listening on a port. So effectively, if you will, inside your app, you will start multiple servers -- one for each port -- but once you have acquired a client connection you can share the same code for all requests coming on all ports (you are listening to).
You'd need to create one socket per port you want to bind. But how this will help you to "monitor tcp/ip traffic coming to your system" I am not sure. Probably it won't.
Is it possible to run a TCP Ping in Silverlight? I know raw sockets are not allowed, which is a big limit. But can you achieve something similar to speedtest.net which does a ping utilizing Flash?
It depends on what you're wanting to do. If you want to do a "real" ping, i.e., using ICMP, no you can't. But if you just want to know whether you're connected to the Internet in some fashion, or if some server is online, you could use the WebClient classes to see if a given web server responds, or if you control the server, you could use the Socket classes to try to open up a connection to a Silverlight-accessible port.