Application testing (Multiple IP's) - java

I've been developing a P2P application that i have to test now. The problem is, that i cant figure out how to test the multiple instances of the application on one computer.
The application is made in Java and I'm running it on OSX. I'm of course getting an error about the address being used.
The test only has to show that packets are transmitted between the different peers in the network.

You should use different port numbers for different peers.

If it's P2P then the best testing is of course on multiple machines. You could setup a virtual environment on your machine and test it using a couple VM's. I'm not sure how to do this on OSX but I would think you could.

If you only need to exchange data between two peers located in the same pc, then using different ports should be sufficient. But if your peer supports many ip addresses, you can try to assign them a different one too.
Keep in mind that firewalls installed on PC can sometime silently kill packets (I've see that under Windows), especially if you use multicasting or loop back addresses.
Last, if you test your application successfully on a PC, it may not work well when deployed on multiple peers, because the network plumbing is complex and tricky. A system where peers share the same IP address usually does not behave like a system where peers each have their own IP addresses.

The problem is, that i cant figure out how to test the multiple
instances of the application on one computer.
You should be able to start up two instances of the application and configure them differently. If you are unable to do this, then connect two computers together, and test it that way.
The test only has to show that packets are transmitted between the
different peers in the network.
You are going to verify the CORRECT packets are being sent, right?

Related

Is there a way to connect two computers with a two-way connection on different networks (one has port forwarding)

I am trying to make a two-way instant messaging app over two different networks. One of these networks is mine, which has port forwarding enabled(sends traffic on certain port to specific ip address). My problem is that I need a two way connection(sockets can only send to serverSockets, serverSockets can't send to sockets). Is there a way to connect to a computer via a pre-existing connection? Is there a library for this? ie. socket.connect(serverSocket.getConnection, 5001); (I have made my own classes which handle all the Input/Output Streams and sockets, I just need a library for a function I can put in the class).
If what you're asking for is to have a computer exposed to the internet to directly connect to a computer behind a NAT, you might get your app working if you are able to implement something similar to reverse ssh tunneling. See here and here, for a java library.
But I would recommend some sort of client-server approach for this, in which everyone connects to the server, and through the server they connect to each other.

Cross-platform server application to communicate with Android/iOS on WiFi

I am working on an application where I need to establish a server on a Windows/Linux/Mac machine which will need to communicate to an Android/iOS device over an existing WiFi network.
I am just in the research phase for now, and though I can find answers for communicating between PC-Android, PC-iOS, Mac-iOS etcetera, I cannot find an answer using which I can do all of it.
The mobile application will be different for both the platforms, of-course, but the server application should ideally be the same, and should be cross-platform.
I should also mention that the server and the clients(mobile-apps) will maintain a 1:n relation, meaning that several Android/iOS devices will be communicating with the server at once.
I need advice on which language/library shall I use for the server which would let the it communicate to both the mobile platforms.
Advice on the libraries I should use for the mobile platforms will also be helpful, though it's not important until I complete the server.
I am just looking for links to helpful resources, though I will be very grateful if you share some code.
I shall also mention, I know Python/Java/C++ which I can use for the server, but you are open to suggest another language which may make the work easier.
EDIT: What I forgot to mention is that, this will be a local server, that is, it needs to communicate with these devices on a LAN (devices on the same wifi network).
If you Know Java for the server side you cab create an application that hosts a RestFull API running on a tomcat server that you call with a local address (such as http://ip_adress:port/appname)
Tomcat can run on Windows, Linux or Mac.
If you need more informations just ask

How RabbitMQ connection works between 2+ endpoints?

I've looked at the tutorial for RabbitMQ RPC. The client and server basicly do the same. Assumed i've 2 or more computer who want to consume from a queue. I wonder how the know from each other if i just pass the own network hostname/ip to the ConnectionFactory. Does this example work on to different machines? (Can not test because of config issues).
Yes, it works on different machines. If you want to connect from a different computer just pass a different Host to your ConnectionFactory.
If you can't connect from a different machine due to configuration problems, perhaps you are using the guest:guest user, which can only connect from localhost? https://www.rabbitmq.com/access-control.html

Pinging computers on a network

I am a researcher at University and I'm trying my hand at a bit of amateur java2 programming.
I've been working through the KnockKnockServer/Client Java2 tutorial to send strings from one program to another using Java Sockets.
http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html
Full source can be downloaded there and it compiles nicely and is a great example of using IP's to get two programs to talk to each other in Java.
This works fine when I use both the server and the client running on the same machine and the machine name as "localhost"
kkSocket = new Socket("localhost", 4444);
And it also works at home when I use it on my home network with a InetAddress:
InetAddress myaddress = InetAddress.getByName("129.11.138.64");
kkSocket = new Socket(myaddress, 4444);
However when I try to do the same on the university machines it doesn't work because they are behind some kind of proxy despite the fact that the two machines are next to each other and plugged into adjacent ethernet ports.
Question:
How to I work out how to get the two machines to speak to each other, when I don't have full control of the network they are on? I can't even work out how to get them to ping each other. I have visited "www.whatismyip.com" to get the external ip's of each machine but that doesn't work, and I've looked at the next work adapters ip and the gateway they are on but still I can't get them to talk to each other.
Any ideas.
Thanks!
It sounds to me like your network is blocking traffic on port 4444. Try a different port, or confirm that port 4444 is allowed.
There are several different parts to this problem:
1) Can the two machines connect to each other?
You can test this from the command line with the "ping" command which is available in both Windows and *nix. Ping tests for the existence and reliability of a connection to the named machine.
2) Could the route be filtered?
Just because you can ping a machine, doesn't mean there is no firewall or proxy between them. You can find the route taken between the two machines with the "tracert" command. The more steps in the route, the more things that might stop your signal
3) Is Java firewalled?
Just because it is installed, does not mean it has open network access. Try fetching a few URLs or similar to see if Java has network connectivity.
4) Is the port blocked?
A port could be blocked in two ways: some other application is using it, or a firewall is limiting listening ports. If the former, Java will not be able to attach a Socket to the port. If the latter, try a different port. There is nothing to stop you running 10000 clients simultaneously and seeing if you can connect to any of them.
5) How do you do this in Java?
Ping can be implemented by InetAddress.isReachable().
6) What should I say to the angry Network Admin guy who has just turned up?
"I'm not port and network scanning! Honest!" Hunting for usable ports is a basic hacking operation. Some workplaces have automatic tools to check for it and will view it as inappropriate.
Even i cannot ping two machines at my work place.
you need to change the network preferences or try the following:
(instructions for IE)
Go to tools-> internet options -> lan settings -> advanced.
Add exceptions to the field: "Do not use proxy server for addresses beginning with:"
enter the networks ip starting numbers, for eg if your network has ip adds starting with 10.--.--.-- write 10.* in the field.
You need to make sure that each machine knows about the other's private IP address on the LAN (see the ipconfig or ifconfig command). It changes (nearly) each time the devices are connected on the LAN, and sometimes even while they are connected on the LAN.
www.whatismyip.com won't help you, because it will only give you the public IP address of the router/NAT which is closest to that server. There is no guarantee it is also the closest one to your devices. Even if it were, this information would be useless, because you (most often) can't predict how the NAT will translate your private IP address into public IP address.
Even if you could 'guess' that information, there is a possibility that the router/NAT might not let you use this translation behind it (i.e., on the LAN).
To summarize it, make sure you use the proper private IP addresses assigned to your devices and make sure that no router or firewall is blocking traffic over the considered port.

Make two Java applications on the same LAN aware of each other

I have a Java program running on two computers that are both on the same network. I would like to have these applications become aware of each other, so they could communicate directly as opposed to communicating with the server to relay messages.
I believe i may have a solution as to how this would work, but am unable to find any examples to compare my solution against. Do you guys know how this problem is usually solved?
There is a good library that implements the Zeroconf / Bonjour standard in plain java at http://jmdns.sourceforge.net/
This basically relieves you from the protocol burden and allows you to advertise and lookup service providers based in logical names (That's what iTunes or Mac printing does for example).
This book http://www.amazon.com/Zero-Configuration-Networking-Definitive-Guide/dp/0596101007 explains all basic concepts.
You could get them to do a UDP multicast within a LAN environment to identify the programs using protocol messages then have a stored cache of each other's identity and then use TCP to connect and do main exchanging of messages (which is more reliable than UDP). Or you can simply proceed with UDP messaging only if you want to.
You can search for multicasting in Java online.
Some multicast related links:
http://download.oracle.com/javase/1.4.2/docs/api/java/net/MulticastSocket.html
http://www.javafaq.nu/java-article817.html
A good multicast chat software you can reference:
http://sourceforge.net/projects/mc2/
One way would be to send a broadcast to see who's out there, then implement a GUI to show the user what other peers are there and give an option to connect to. (The broadcast will give you the IP address of everybody there.)
Once you know who to connect to, you simply open a TCP connection (or use UDP if it is time-critical) and you're done.
Btw, this is for IPv4 - IPv6 doesn't have broadcast (although something similar).

Categories

Resources