Java. Communicate two peer-to-peer applications - java

I am studying communications in Java using RMI and in all the references that I find there is a client that makes calls to remote methods in a server.
That is, all communications are initiated by the client.
If I wanted two computers to communicate as equals, would it be right for each of them to implement a remote object? That is, the two applications would play the role of client and server.
Thank you

If you are creating desktop application, you could use sockets for communications between many computers.
A socket is one end-point of a two-way communication link between two or more programs running on the network. Socket classes are used to represent the connection between a client program and a server program. More.
Example code for server/client applications
You should know that you will need a bit of knowledge about concurrency and networking to create good communication between many computers. Creating simple server/client applications is very good way to achieve it :)
Please remember that client will always need IP:PORT address to connect to server.

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.

Java Server and client/ RMI or Socket?

I'm developing a Desktop LAN base java server and client application
where a Client must login and also to pass some data to server.
assuming i have 10 clients that inserting record simultaneously to server.
which is the best approach in this kind of situation, should I use RMI for login and record insertion? or Sockets?
if sockets please provide a key idea for me to start with.
key points to consider
-Multithreading
-able to send back data on client
If you want to connect your server via internet (and/or firewalls) it is probably a hassle to do this with plain RMI. In the past I have used Java Simon for such tasks which is very easy to implement. However if you plan to support other clients than Java clients, then you should have a look at Apache Thrift or Google Protocoll Buffers

Client and Server socket connection

I'm new in java, and I have a problem. I have two android phones (Client and Server). Can anybody say me how to display on Client application the Server IP address?
Kryonet is a very good Java library which provides a clean and simple API for efficient TCP and UDP client/server network communication using NIO. It works on Android as well.
It will make your network programming work a lot more easier, and you can get a better understanding of how to write client and server side code.
I would suggest that you try out your network programming skills using this library.
You need not even hard code any IP address of the server while in LAN. The clients can discover the server in just one line of code.

Java RMI for implementing server side of system

I am developing system, that consists of client (written in JavaFX) and server. Now I am going to implement server. Users will download clients. Clients will communicate with server (only one server and many clients). Server will communicate with data base and send results. Server will support authentication and different requests (not http of course). Is it a good idea to implement server with Java RMI? If no, could you advice me any good idea about server realisation.
Thanks a lot for future questions!
RMI is bit kind of traditional but still powerful to me ,it has some draw back . But, despite the RMI there is also a chance for you to use java sockets class ? just like a client -server application ...

Client server application - Best approach in Java

Need to create a client server application, both have to communicate with Database. Which approach suitable for this,RMI, Socket programming etc....
If server communicates with database, I think that client should not (according to layers/tier ideology: http://en.wikipedia.org/wiki/Multitier_architecture).
Or if your client works directly with database, than you could avoid usage of server.
For client-server communications you could use a lot of options: RMI, sockets, webservices, etc.
If you have an experience with java web applications, I suggest to use webservices, if not - RMI.
When I took my 1st module about client server application in my University, they taught me about RMI & Socket programming. In my opinion, if you want to have basic knowledge about client-server communication, RMI & Socket programming should be useful. However, if you need a solution that you will bring into production system, you should take a look at EJB with JSP/JSF.

Categories

Resources