I have to make a java program in which there are some processes that communicate using HTTP
sockets. But I found that there are only TCP/UDP sockets in Java.
I am little bit confused here. Is there anything like HTTP Sockets ?
Is there any library in java that provides HTTP sockets ?
The processes in my program run on the same system spawned by a single main java program.
I need some way to communicate one process with the other.
Related
I have a requirement where I need to send message from multiple clients and those clients can be C clients or Java clients to server written in java.
Why I need to send over socket? Because there can be any process in any app on a same system who wants my app to capture there alarms and react accordingly.
Now, I can implement multiple Java clients who can connect to single Java server but how to do the same thing irrespective of it is Java client r C client.
If not socket programming, then what could be the other best way to make this communication happen
All low level network programming is written using sockets. you can have server written in any language communicate with client written in any language. To make this happen we have certain protocol which governs the communication like udp, tcp etc.
high level language provides api which will you to connect any server with single line of code without you needing to create socket. But in C you can create socket and connect it to the server. see this. All you need to know connect server and client is server ip and port...
While your requirements are very broad it looks a lot like a prime candidate for protocol buffers.
https://developers.google.com/protocol-buffers/
Language agnostic.
Platform neutral.
Fast.
Running on ZeroMQ (http://zeromq.org/) where you can push and pretty much run on top of everything.
I'm new at java but I 've experience on as3. When I was using as3 , I was using some callbacks to notify both server and client when I send either of them a message from the other. But it was a pre-build server named player.io. (as I recall, server was built with c#). There were listeners for messages on both client and server.
But as I started practicing sockets on java, all the examples I saw implement BufferedReader and readLine methods to recieve data from server or client. Problem is , this method waits until it receives data. And this waiting is ofcourse is a big problem, especially for the client.
Is there any way to use callbacks or other methods for communicating between server & client which doesn't cause either of programs to wait?
I am trying out a simple socket programming example. I was able to run a server application and client application to communicate with each other. I now need to know a tutorial that explains how 2 clients could communicate with each other through the server.
How can I do this ? Can someone point me to a good tutorial or an explanation on how this can be done in Java
It's not that different and difficult than writing client/server pair. You just have to create threads on server just there, where you accept connections from clients. If your clients should communicate each other, than you surely need a list to store them. And you have to implement, what your server does (communication) in this thread.Here is a good chat programm tutorial: http://www.dreamincode.net/forums/topic/259777-a-simple-chat-program-with-clientserver-gui-optional/
Considering application_A on a machine_1 needs information about machine_2, provided by application_B (which is located on machine_2) and that both machines are in the same network, what would you guys suggest to be the easiest way of implementing the communication between the 2? (I was thinking simple socket connection).
Note: the information required is something in the lines of a few bytes, so nothing big.
You can either use socket based communication or Java RMI.
I would recommend Java RMI as its easier and saves you from handling raw socket communication.
If you are familiar with Spring framework, then writing RMI application in spring is very easy. Check Exposing services using RMI (Heading 17.2)
There are different ways to implement this but they all come down to one thing: communication over sockets.
If the information is only some bytes, implementing the sockets themselves is probably your best bet, if things start to get bigger, you might want to look into some middleware.
You can run a server program on Machine2 using ServerSocket and a client program in Machine1 can request for info.
You can try web services. JAX-RS would be the simplest.
I've a doubt in java socket programming. The tcp server is created Java Socket Programming and running in different machine. Now I want to create a client for the server to request some data from server. Am I need to use same Java socket programming or I can use different APIs to communicate with server and get response back?
Thanks,
Pramod
You must also use sockets, but not necesserily in Java. Virtually any programming language can talk to different machines based on TCP/IP or UDP sockets. You can even use tools like nc to test your server.
If the server is using sockets, then yes, the client should also be written using the sockets API. This can be done in any programming language, not necessarily Java.
To give you a broader perspective, there exist other technologies that allow two processes to communicate (RMI, zeromq etc). However, it is almost always the case that both sides of the communication have to use the same technology to be able to talk to each other.