Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I were wondering what's the proper way to create a chat/communication software in Java for Android?
I guess it's a Socket (TCP/UDP).
If I do it my own way like using a web calls for PHP with backend scripts why it is not so appropriate way to create a chat? What's the difference between them? Using a calls instead of raw sockets? Does it use more battery or something? I just feel that sometimes it would be more easier to parse a JSON for messages and send data through web calls, but I feel that it's not a proper way to do so and application may have a critical issues like draining a battery or something which will make the project to be discontinued.
I would like to be sure is there any other ways to create a chat, than sockets and do every famous developers use a sockets as primary method for creating a communication software?
The protocol could be Socket or others such as XMPP
If you prefer using Socket, SmartFox might be one of the libraries that you can rely on. Smartfox offers SDK for a number of languages such as C#, Java etc.
Note however, that if you use socket for communication, usually json is NOT used, since most of the times, binary objects are used in the socket-based communications, say for example, SmartFox uses ISFSObject, which wraps all the data into a binary object.
Below posts might be useful for you to get started, though it is not written in java, but essentially the workflows are exactly the same.
Using SmartFox with C# (I) : Installations and 1st handshaking
Using SmartFox with C# (II) : Login and join room
Using SmartFox with C# (III) : Frequently used functions
Apart from the socket and xmpp appraoches, you can also opt to use WebRTC, where there is no such kinds of servers, and peer to peer communication is used. A good tutorial can be found here.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
So usually, to have get and set methods in networking Java I use an enum, for example:
public enum MyEnum {
GET_NAME,
GET_ADDRESS;
}
etc. which the client application and server application would send between each other as a string and the appropriate task would be carried out.
I wanted to know how applications do this usually? What data do they send through the socket to make the program work, do they use ObjectStreams? Do they send bytes?
Wanted to know what the best practice would be to have a client-server setup for my own messaging application.
EXTRA INFO:
The client / server network I'm designing is for a PLUGIN in a GAME and therefore has to be instant / speedy ;)
All of that. Or something else.
The "industry" standard can be many things, depending on the domain you are looking at, or the decade when the solution was designed.
In 2018, most "new" client/server communication that gets defined doesn't operate on socket level. You rather define a set of restful APIs that the server offers, and data flows as JSON strings for example.
In other words: the official answer here is: there is no such as an industry-wide standard. To the contrary: what you are asking about (sending individual comments on socket level) is probably the exception, and not something that is common for real world architectures. People don't think in sockets and single commands. They think in terms of protocols, abstractions, maybe "remote procedure calls".
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm creating a simple java application made in swing that communicates with a database. Multiple people will be using the application at the same time. As they are able to change things at the same time, if someone for example, adds a new user, and a different person is on that same page, I want the person who did not make the change to be notified that changes were made to the database since they last loaded it.
My lecturer in college advised me that WebSockets would be the way to go to achieve this, however after some reading about WebSockets in Java, it seems it is based to work with web browsers instead of between Java applications.
Can using WebSockets achieve what I am trying? Or, if not, what would be a way to achieve this?
Simple answer is Yes you can achieve what you needed
WebSocket is a communication protocol(#see RFC 6455) & it is not a must to use a Web browser.
You can achieve what you want to do with your app, it is just a matter of writing a custom WebSocket server to facilitate your requirements in your case sending database changes to the other clients(Which is called Server push)
There are several java libraries to get the work done,
netty WebSocket (My favorite)
jWebsocket
Atmosphere
Webbit
Netty WebSocket is a good one to start with and you can find examples in its project to write a custom client and a server
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have searched for some hours now, and can't find an answer. I have a homepage coded in php that needs to frequently send and receive data to a java program.
So far I have done it via POST, but I wonder if it's a better way to do it. I have tried with sockets. But only managed to find tutorials for php client connecting to a java server. But I need the reverse.
All modern languages allow you to send and receive data, no matter from which language is sent or received. Many large applications (such as Facebook API), work with simple methods such as POST, GET, PUT, DELETE, etc., that is a REST API, returning the data in a specific format (JSON, XML, RAW, etc.). This is innecessary if your application is a little piece of code, but you could take this idea and make something simple. So, there is nothing wrong if you are using the POST method, but just in case, I can name you other resources that you could take advantage of.
You can use WebClient.
Also, you can comunicate your PHP code with your Java code using sockets.
TCP sockets: for PHP read this, and this guide for Java.
WebSockets: Java WebSockets for Java and Ratchet for PHP.
Of course, you can use cURL too. For Java you can read this question and connect with php. If your application is very large and complex in the PHP side, I guggest you to use Laravel.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I understand that Socket-based Communication is independent between programming languages. Which means, a socket program written in Java language can communicate to a program written in C or C++ socket
program. And I've see many similar questions like mine in Stack overflow and I appreciate those answers.
But I didn't get what I'm looking for. Can anyone answer this with example code as JAVA program as a Server and C++ program as Client which runs on different machine and how they communicate?
Thank You :)
Socket communication is basically sending a set of bits (data/packet as you would call at a higher level) from one port to another. Port is nothing but a file/IO stream that can listen to data or send data given the correct address. A valid address is a combination of valid IP address(depending on if you want local or remote communication) and port number.
To answer your question we basically are opening a file, writing or waiting to be written into from another application. So, file open, close, read, write has nothing to do with a programming language. Only thing that varies between different languages are the APIs or interfaces provided to achieve this purpose.
When you open a socket you mention about the protocol you want to use for this communication, it could be TCP/UDP based on the purpose of your application. The protocol decides how the packet/data being sent and received are ordered. Basically, trying to establish a common ground between the 2 parties trying to communicate.
Hope this answer helps!!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have some very basic doubts on this topic.
I have a legacy server written some 30 years ago in C, C++, that supports socket communication but it works great.
I am in the process of writing a new java based client to connect to this server basically the goal is to expose the services (REST etc) for enterprise applications.
1) Should i go for plain java socket based approach or use Netty or Apache-Mina, what benefits i may have by using these modern apis in this scenario.
2) When using NIO based IO, does the sever also need to be a NIO based to take advantage of it or a NIO client to a legacy server (non NIO) would just work as good as it does with a NIO server.
Thank you very much
1) Should i go for plain java socket based approach or use Netty or Apache-Mina, what benefits i may have by using these modern apis in this scenario.
I assume that you mean using plain Java sockets to implement HTTP / REST-ful APIs.
That is a bad idea. It is theoretically possible, but you will end up doing a large amount of unnecessary coding. And the chances are that you will not implement the HTTP 1.1 spec properly ... and that will lead to further problems.
As for the others, I'd take a look at them, compare their features against the features you need and decide based on that ... and how easy to use they look like to yout.
2) When using NIO based IO, does the sever also need to be a NIO based to take advantage of it or a NIO client to a legacy server (non NIO) would just work as good as it does with a NIO server.
What you do on the client and server sides (NIO versus non-NIO) is independent of each other. Indeed, if you do REST properly, the client and server sides shouldn't even need to be programmed in the same language!