Java bacnet4j communication over Network - java

I am able to get my virtual bacnet4j devices up and running. as I am running them on One windows machine i have used set of ip address 127.0.0.3-10.
I have a virtual Bacnet device which monitors other devices, which work fine when its on address 127.0.0.2 (or any other address starting with 127.0.0.* )
However I am now puuting it (Monitor) on Actual different windows machine running on IP say 192.168.2.3
My machines IP address on that Networks is say 192.168.2.2
Now The Monitor and devices won't recieve any broadcasted messagesfrom each other.
Any idea's if its achievable?
I have already tried using link service option within bacnet4j.
Now thinking of writing a bacnet router myself to achieve this. but wanted to confirm if What i am thinking is right? or is there a better way to achieve this communication.

The obvious: Any firewall activated?
Can you ping the other machine? Just to cover the bases.

Related

Detecting wi-fi or cable network interface by mac address

I'm try to detect a network cable interface using it's mac address.
On some machine there is many type of adapter (cable, wifi, usb dongle, etc).
Is it possible to have the types of each mac address, such as wifi/cable/other?
The primary application is a Java program, but other languages would be useful too.
You can get your machine's current MAC in Java; you can't get remote MAC addresses.
Get MAC address on local machine with Java
If you were to connect the computer to the network one way, get the MAC address, and then remember that, you'd have it.
It sounds like what you want is a regexp to tell you if a particular MAC address is a wifi device, a cable router, etc; I don't think the space of MAC addresses was well enough designed to reliably allow for that, and you'd still miss cases of MAC spoofing.

How to test broadcast udp packets in Java on the same machine?

Can I perform a UDP broadcast packets on my machine? I don't have a network, i just have my cheap linux box. I want to have a server broadcasting a packet and two or more clients in the same machine receiving them. Is that possible? What IP do I use?
#gravyface gave me hope but I tried: 1) server sending to 127.255.255.255:54321 and clients listenting to 0.0.0.0:54321. 2) server sending to 127.255.255.255:54321 and clients listening to 127.0.0.1:54321. 3) server sending to 127.255.255.255:54321 and clients listening to 127.255.255.255:54321. None of them worked! :(
OBS: I am using REUSE_ADDR and SO_BROADCAST options.
I am able to confirm that 127.255.255.255 works on Linux (Ubuntu) and it does not work on Mac (Snow Leopard). If you ever find out how to do that on Mac let me know. :)
You can use virtual network adapters with different virtual addresses. For example in Windows you can use Microsoft Loopback or TUN/TAP in Linux.
Another solution would be to create an internal network with a Virtualization software such as VirtualBox but this would require a slight faster machine. If you could only afford(since it's a cheap box) a single Virtual Machine you could enable 1-4 network adapters that would allow you to bind your different UDP clients individually on each one of the virtual adapters of your virtual device.

BACNet plugin for Building Management System

I'm trying to get a BACNet scanner up on an Seimens server running the Apogee system with a BACNet interface. I've tried using BACNet4j put i get a port bind error on the LocalDevice object for test/Scan.java.
Does anyone know of any other libraries I could use or a reference to instructions for setting up a BACNet plugin to a building management system?
I have had the same problem before, i.e. the BACnet client needs to both send and receive from UDP port 47808. Since the BACnet server already uses that port to listen (and reply) my solution was to use a virtual IP (a bridge) so that my client runs on the same Ethernet card but with a different IP address. A bit convoluted, I know, but it works.
Whether or not the Apogee system supports virtual (or simply additional) network drivers is another question altogether. On my Linux and Windows machines I can run as many servers and clients as I need (I actually don't know what is the limit, I have run up to 5 servers and 3 clients without any problems).
Concerning the port bind error, you may have to configure your firewall because:
BACnet/IP is using UDP
the default port number is 47808 (0xBAC0)
Your issue might be the use of a (BACnet port #) socket that is already in-use; you have to ensure that it's not in exclusive-use - before binding to the socket, but also (slightly more) important, also ensure it's marked for reuse.
But unless you're listening for Who-Is broadcasts, I'd recommend listening for the (unicast) responses upon a different port #, e.g. 0xBAC1/47809, but still send upon the standard port # 0xBAC0/47808.

Communicating between Android phone and PC using TCP in java

I'm working on a project where I want my Droid 2 to be able to send and receive data over 3G, to a device connected to an ethernet port (not necessarily a PC, but I'm using this for testing the communication). I believe that eventually the end to end communication will be accomplished over an SSL tunnel, but for right now, I just need to establish basic communication to show that the devices can communicate.
I've written some client/server applications that worked between two computers on the same network, but I'm not sure if the communication in this case will work because of the different networks that the phone and PC are on.
I've been trying to establish if this can be done by pinging some of the PCs at my University and house using a pinging program I got off the market, but I've had no success so far. However, my friend has rooted his phone, and was able to do so.
I suppose this question really has two parts: 1) Is this possible? and 2) Do I need to root my phone to accomplish this, or should I be able to do it without rooting?
Thanks for any responses.
I've never worked with Android phones but I think:
You do not need to have a root access to use sockets;
You said that you want to use 3G to connect to your home PC and I suppose you have some kind of router at home and you need to configure port mapping from your router to your desktop.
I've written some client/server applications that worked between two computers on the same network, but I'm not sure if the communication in this case will work because of the different networks that the phone and PC are on.
One potential problem I can see is that, depending on your 3G provider, there may be a restriction on port numbers and protocols that can be used. For instance, HTTP to any port number may be allowed but unknown packet data (i.e., an unidentifiable protocol) to the same port numbers that work for HTTP, may be dropped.
I've been trying to establish if this can be done by pinging some of the PCs at my University and house using a pinging program I got off the market, but I've had no success so far. However, my friend has rooted his phone, and was able to do so.
Again, another potential problem - ping (ICMP) is not a good test of accessing devices on other networks as most perimeter routers/firewalls will by default refuse ICMP traffic (usually silently) - even my home DSL router/firewall silently blocks ICMP by default. As for needing a rooted phone to be allowed to use a ping app - my phone isn't rooted and I have a ping app from the market which works fine.
I suppose this question really has two parts: 1) Is this possible? and 2) Do I need to root my phone to accomplish this, or should I be able to do it without rooting?
There is no reason I know of that would require a phone to be rooted to use socket-based comms, I'm just wondering if trying to ping across a router/firewall isn't the best test for what you are trying to achieve.
I'd recommend starting with HTTP - I don't know what you use to program for the PC but a simple HTTP 'listener' should be easy enough to put together. Start by listening on port 80 and try from the Android browser - if that works, change the listening port to something like 6789 (remember to open the ports on your home router/firewall). Assuming you've got that working, try using the socket-based stuff you've developed using wi-fi on your LAN, if that works, then try over 3G.

How do I send data between two computers over the internet

I have been struggling with this for the entire day now, I hope somebody can help me with this.
My problem is fairly simple: I wish to transfer data (mostly simple commands) from one PC to another over the internet.
I have been able to achieve this using sockets in Java when both computers are connected to my home router. I then connected both computers to the internet using two different mobile phones and attempted to transmit the data again. I used the mobile phones as this provides a direct route to the internet and if I use my router I have to set up port forwarding, at least, that is how I understand it.
I think the problem lies in the method that I set up the client socket. I used:
Socket kkSocket = new Socket(ipAddress, 3333);
where ipAddress is the IP address of the computer running the server. I got the IP address by right-clicking on the connection, status, support. Is that the correct IP address to use or where can I obtain the address of the server? Also, is it possible to get a fixed name for my computer that I can use instead of entering the IP address, as this changes every time I connect to the internet using my mobile phone?
Alternatively, are there better methods to solving my problem such as using http, and if so, where can I find more information about this?
EDIT:
Would it be possible to have the server program running on a server on the internet somewhere. My original server would then be a client that send information to this server. This server would then pass this information to my original client and vice versa. That way, the IP address of my computer won't matter, as I only need to know the address of the server hosted somewhere on the web. Does this seem like a better solution? Where do I begin implementing such a solution?
Thanks!
When you connected to the server that serves StackOverflow, did you type in the IP address? It's 64.34.119.12, if that jogs your memory.
You probably didn't. You probably typed "stackoverflow.com". There's a huge, complex, clever, and in some ways, poorly implemented system called DNS that translates sensible and human-readable names into IP addresses.
One problem with DNS, though, is you need a "static IP", which is exactly what it sounds like: an IP address that doesn't change, which is exactly what you don't have.
So, what can you do?
You can buy a static IP account from your ISP (pretty expensive)
You can use some proxy out in the Internet (a machine that does have a static IP and is willing to bounce your packets back and forth -- I'm not aware of any service that does this for you; you could write one and put it up on Amazon Web Services or Google App Engine, both of which would be free at your level of usage, but they'd be slow, since every packet trying to cross your living room would have have to go via some data-center in Virginia).
You can keep doing what you're doing, looking in the net-configuration of your machine.
You could speed (3) up a little by having your server program look up its own IP address and print it out where you could see it and type it into the server by hand.
You can use DynDNS, as Sergey mentioned (this is the "right" solution, in that it's very general, it just might be a little complicated to set up)
You can use multi-casting.
Multi-casting is an interesting solution, and it may work for you. The idea is, when your server starts up, it announces to the net, "Here I am, I'm providing X server, here's my IP address, talk to me." The problem is, a multi-cast won't leave your living room. Obviously, if every multi-cast were spread to every computer on the Internet, the whole thing would collapse, so your router will ignore, and not route, multi-cast packets. That may or may not be a deal-breaker for you. EDIT Re-reading your question, I see it is a deal-breaker for you. I'd go with #5, but be aware there may be routing issues (address translations that prevent a server from knowing the address that other computers can find it at) or fire-wall issues (that is, your ISP may prevent your server from receiving incoming packets even if the address is correct).
using a direct socket connection with a port like 3333 is usually complicated because different network configurations.
firewalls will make a pleasure preventing the connection, or killing it from time to time.
maintaining a 2-way connection can be a nighmare. the SIP protocol is struggling with this kind of problems.
For a simple application, i suggest you look into the comet technology, where your clients can establish an http connection with a shared server. The server can then bridge commands between them.
html5 will also bring the websocket protocol to the table.
I got the IP address by right-clicking
on the connection, status, support.
Not sure about the "support" part, and I'm not on a Windows machine right now, but I think that the most easy and reliable way to figure out the IP address on Windows is to run "ipconfig" from the command line (Win+R, type "cmd", then "ipconfig" in the opened window). This, of course, should be done on the server side.
However, the problem is that depending on the ISP your IP address may be not within the Internet, but within a local ISP network (so-called NAT). In this case, you'll need to use some sort of black magic called TCP hole punching, which is very complicated and not guaranteed to work. You can figure out if your address is local or not by looking at it. For IPv4 local addresses are almost always like 10.x.x.x or 172.16-31.x.x, or 192.168.x.x. Don't know about IPv6.
You can also check your IP by visiting one of the special sites like www.whatismyip.com. If the address they tell you is different from the one you see by running "ipconfig" or looking at the connection properties, then you're almost certainly behind a NAT (or your ISP is using a transparent proxy, but that's rare).
If you are directly connected to Internet (no local addresses and NAT), then you should also check if you have any firewall software and either to configure it to allow connections to the port you use, or make sure it's in "ask the user" (and not "silently reject") mode, or just disable it completely (this may put your computer at risk, especially if there is no anti-virus software or the system isn't up-to-date).
Also, is it possible to get a fixed
name for my computer that I can use
instead of entering the IP address, as
this changes every time I connect to
the internet using my mobile phone?
Yes, it's possible. There is the thing called DynDNS, and there are DynDNS providers like DynDNS.com, where you can get a third-level domain name for free (like mycoolpc.dyndns.org). You'll have to install and configure some DynDNS client on your PC that will tell the DynDNS server its new IP each time each changed. I don't know anything about particular clients to use because I'm using the one built-in in my home router.
No need to write networking code for this, unless it really floats your boat. Take a look at SCP. http://amath.colorado.edu/computing/software/man/scp.html. There is a windows implementation where you can download putty (windows ssh client), and it is on most linux distributions. Alternatively, you could set up an FTP or SSH server on one or both of the machines.
"a fixed name for my computer that I can use instead of entering the IP address" would be a domain name, these are purchasable online for a few bucks.

Categories