I need to make Android application which can send TCP queries to an embedded RS-232 system (connected to a router).
Unfortunately, no IP address was given because each embedded system has a different IP address.
To learn the IP Address, an android device (tablet/smartphone) must connect to the local wireless network and acquire the address of the embedded system. The local network also has a public IP address which enables the embedded system to communicate with the outside world.
My task is to send queries to the embedded system and get replies from it. The protocol is RS-232 for both input and output.
Please, give me an idea of where to start. Thank you.
Scan the network for the open port if there are no zero config options.
If you know the range of mac addresses the devices use you should be able to filter them out using ARP.
In case you can control both ends you can use multicast and save the discovery step.
Alternatively you can use dns-sd, but again the embedded system should be aware of it.
At the end, if none of the above options are possible you should scan the network as mentioned in other answer, but if DHCP is used you will never know if the address you obtained is still valid.
If you are talking about on the same network you could use a UDP broadcast which is picked up by the device which contains the remote ip, which then sends a response to the android handset with it's own tcp ip address.
Related
I'm developing multiple applications which need to communicate with each other via socket. First I need them to be able to communicate on localhost. So when I'm running both of them at the same time on my phone they can communicate (I know that there are easier ways to do this on the same phone but in the future they will run on separate phones).
My code for socket communication is very similar to this: link
Difference is that my apps are running this as foreground services.
I've set the ip for the server on the client to 127.0.0.1 but they just won't connect (not in the emulator and not on real phone). What am I missing?
UPDATE:
I've found an easy way to get the device own IP address, so instead of localhost I use this (with www.google.com domain): answer to "java InetAddress.getLocalHost(); returns 127.0.0.1 … how to get REAL IP?"
Maybe it's not too nice but it works.
You'll need to set the local IP address of each one, so they can communicate within your LAN. So use an address like 192.168.1.X. Both if you're running your devices as virtual or physical, you may easily know the local IP address they have accessing your router's web interface and seeing their bound IPs.
I have a TCP server running on a specified port (23232), and an Android app that needs to connect to the IP and Port of this server. Is it possible to obtain the IP by scanning for a port only? I have media player control apps that do this but I have no idea how to implement it.
Thanks in advance.
This is on a local network, correct? I would recommend that you use a multicast service discovery mechanism via UDP, since this is the exact kind of scenario it is intended for. Fixed port, unknown entities on the LAN providing the service.
I want to search the local network for special servers to communicate with. To achieve this I'm running a for-loop pinging all IP-Addresses in the range I give the function.
E.g. findServers("192.168.0.x", 101, 255) pings all addresses between 192.168.0.101 and 192.168.0.255 and, if they are reachable, tries to connect to a specific port to find out whether a server is running.
But I don't want to enter the range manually. Is there any way to get the IP-range in which the DHCP-server assigns addresses to the machines in the network?
The only way to obtain this would be to ask the administrator of the DHCP server. One remote possibility is if the DHCP server exposed an SNMP server as well and that SNMP server provided the information. However, no sysadmin worth his/her salt would expose that information, so it's unlikely.
In short, the answer is about 99.9% likely to be "you can't".
You can look at the subnet for your machine and try to connect to the port in question. This saves you needing to know the specific address range the DHCP will give out.
You don't need to determine if the host is reachable because you would still have to attempt to connect to the port. If you connect to 255 addresses using a thread pool it will take a few seconds.
Instead of using TCP you could use UDP. UDP can send a broad cast to a whole subnet or multi-cast across networks with a single packet. This would allow you to send a request to any number of machines to find out if they have a service available.
There is no such protocol that propagates the available ip address range, provided by the DHCP server.
I know its old but maybe someone Google it. You can get it with PowerShell:
$dhcpserver = "10.17.5.1"
$ScopeList = Get-DhcpServerv4Scope -ComputerName $dhcpserver | Where-Object {$_.name -like "*toip*"}
ForEach($Scope in $ScopeList){
$voip += Get-DhcpServerv4Lease -ComputerName $dhcpserver -ScopeId $Scope.ScopeId
}
This will only work if the scopes for Voips have a pattern like "toip".
I have fully developed a chat room for multiple clients with multi-threaded server which does the job, however only on my local machine. I want to go beyond this, and make this chat room to be working over the internet. So far I have made the port forwarding on my router for TCP protocol to route to my local IP address, however this didn't solve the problem and I still can't connect the client, even on my own local network. What other steps should I follow to get my chat room working on my own local network and then the internet?
try disable (windows) firewall ?
So my friend the basic rule for make anything to work over internet is to do Port forwarding or in simple way you can say that to open your server for the public network. For that you need to make sure that the routing path is complete from internet machines to your desktop. For this to work you need to open the port for which you need to access your machine from firewall settings, and also ensuring that trafic is routed from your public IP address to the server's IP as your server will be private under some router or ISP.
Way to do that:
You need to configure your home network i.e router setting. So in your router, configure the port you want the communication to happen(say port 5443).
In your router, configure a port-forward for the port 5443 to the internal IP address of your actual server, also to port 5443.
Reference: https://www.noip.com/support/knowledgebase/general-port-forwarding-guide/
On your server(your Desktop Machine) ensure that your firewall settings for port 5443 is on and set to allow rather than block.
I want to simply connect two machines on the same network via a TCP Server/Client socket connection.
Right now, I need the IPv4 address from the machine hosting the server in order to connect the client.
localhost works fine when I'm running the server and the client on the same computer, but that's not very useful.
Is there any way around having to manually punch in the IPv4 of the host computer?
Thanks, this will probably clear up a lot of confusion.
Use a broadcast to send all clients a message. (this could contain the servers IP but think about that! it could be a security issue)
There are good examples on sending broadcast messages with java
Broadcasting to Multiple Recipients
If you know the name of the hosts, then you can also pass these names in a config file and use getaddrinfo() to get the IP address of the host: http://man7.org/linux/man-pages/man3/getaddrinfo.3.html . Since hostnames do not chnage frequently, this should provide good improvement as compared to manually punching the IP address.