How RabbitMQ connection works between 2+ endpoints? - java

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

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.

Is it possible to connect to a mail server without hard coding the port using JavaMail api's, basically the code should be independent of ports. ?

I am working on an application where the app should able to read/fetch the emails from a smtp server. The problem is the ports may differ in different environment. Is there any way to connect to smtp/pop (microsoft exchage) server without knowing the port. Any information might be helpful because of I am new to this javamail api's.
There are standard ports for these services, which JavaMail uses by default. It's relatively rare that one of these services will use a non-standard port. But you do need to know whether the service requires SSL or not, and there are two standard ports used for SMTP. You could easily write code that tries all the common ports and you would probably cover 99.99% of the cases.
I don't think that would be possible. Each port serves a different purpose.
What you can do is read your port number from an external property file, so that your code becomes environment independent, and then you just have to change the value in your property file which placed outside your deployed war/jar
This way, your port no value could be environment specific without having to change your code.

Java router port setup programmatically

I'm wondering if there is a way to setup connection between a client and a server over the internet and have both of them programmatic setup all needed router/firewall configuration changes to open needed external ports to communicate.
Assuming both server and client have known ip addresses and a DNS is not needed in this example to find the IP addresses. How might one have a server that when started configures access past the firewall and tells the router how to route proper communication to the server. I would assume the client may not need anything like this as it should only need to know the external IP address and port number of the server. If i'm wrong about my assumption please let me know.
Example if I have two houses house (A) has a server and house (B) has a client and both sites know what the other house external IP address is and know what port they will be using how may a Java application do all the configuration or at least do as much as possible on say windows,mac,ubuntu. The idea is the user of the server and client should not have to do a bunch of firewall/router configurations to get the application running. It would also be nice if in the example it shows how to release the connections when the server is terminated. Example when the java server is turned off it should close up port settings on the firewall and router. security and clean house.
There is no easy way of doing that as it will depend on the OS and on the many possible firewall application running on the machine. Plus, if your app crash, you will never set back the original parameters, which can be problematic when talking about security. Instead of trying to set up custom configuration, you should try to use standard communication template/protocol like http. This will gives you a high probability of your app running without additional configuration almost anywhere (since there is almost no point of having an internet connection if you don't allow http port).

Application testing (Multiple IP's)

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?

Communication via internet in Java

What I mean is like servers on video games. You can run an application and it will set up a server on your computer with an IP and a port.
For example, how would you make an application where one host application sets up a thing where it has an IP and a port, and another computer that has access to the internet as well can type in the IP and port and it would be able to communicate with the host? I mean simple communication, like sending a boolean or String.
And would there be any security problems that would be needed to fix?
I guess I grasp the concept of your question...
You want two computers to connect via internet right? If that is the case, then you will have to use a thing called "sockets" that do connections between computers. About the server thing, well, for starters the client must always know what IP the server as (direct IP or by a DNS), and then you can connect your client to your server. There is a tutorial for sockets at the java pages: http://download.oracle.com/javase/tutorial/networking/sockets . About security issues, well, you must make sure that your server can handle anything that comes from the client (i really mean everything), i mean, accepting every type of data that is supposed to receive and deny everything that is not (trash per say). If you have that in mind then there is no problem (and of course, the server must have a firewall also to control the sockets, but that's not up to you).
Here is an example of how to use sockets to send a string from a server to a client.
http://www.java2s.com/Code/Java/Network-Protocol/StringbasedcommunicationbetweenSocket.htm
The site has about 20 examples of how to do what you are trying to do. In general I find this site to be the best JAVA resource that I know.
In general, the thing you probably want is a Socket. Sockets allow you to send bytes to an endpoint via TCP or UDP. This is very low-level, though, and are somewhat tricky because you have to design your own application protocol. You may want to use something that offers more abstraction.
Java sockets expose a stream interface so you could just encode integers as strings, for instance, and send them line by line, or you could do something fancier and more efficient like using a DataOutputStream to wrap it.
Handling the following issues can improve security.
If you have router ,set different ports for routing.
Example: If you are running server say on port 6001, map a virtual port say 9001 , which would be exposed to public.
DDos
IP Restriction - Not every user can access your machine !
Enabling router firewall does handle most of the issues.

Categories

Resources