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.
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 was wondering how, if possible, could the task of creating/emulating a java serversocket in C++ be performed? I'm new to C++ but I'm fairly proficient in Java. My server (written in java) needs to receive data from all both Java/C++ clients (data is transferred using JSON Strings) but I'm not sure how to establish a connection in C++ with the NIO Server.
Thanks in advance for any help!
Start by reading the following man pages:
socket(2)
bind(2)
listen(2)
accept(2)
connect(2)
After you determine whether you need to create a server or a client-side socket, you will then proceed to implement it using the appropriate combination of these system calls.
A socket is a socket. Whether or not the other end of the socket is an application written in Java, C++, Perl, Ruby, or any other language, it makes no difference. All sockets are created the same way. It does make a difference in terms of the format of the data exchanged across the socket, but looks like you have that covered.
I am about to write a client-server application (a simple game) and I want to use Erlang for the server side and Java for the client side. How should I make the connection between client and server? I have never worked with network programming before...
I think that "sockets" is the thing that I should use, am I right? In that case, could I use Java's sockets-class to send/recieve messages on the client and some corresponding sockets-module in Erlang on the server? Or do I have to have some kind of Java receiver on the server and then translate to Erlang? Is sockets some general protocol sent over the network that all languages interprets?
Depends on what you want to learn.
Sockets are low level and you will need design a protocol.
HTTP Rest API is more general, requires web server (yaws for example)
or Jinterface Erlang<->Java bridge
http://www.slideshare.net/dennisbyrne/integrating-java-and-erlang-with-jinterface-presentation
Indeed, Erlang provides a module for Socket programming that you can use. Go with your option number one.
But is such low level programming is a must for you? If not for your game, then consider creating a REST API. It is HTTP after all. Thus you can achieve:
general protocol sent over the network that all languages interprets
Another alternative to sockets and HTTP for creating
some general protocol sent over the network that all languages interprets
is something like Apache Thrift or other interface description languages (IDL). While it doesn't support all languages, it does support both Java and Erlang.
I'm developing a Client application which talks to a Server using WebSockets. The Client is in C++ and the Server is in Java.
Can anyone suggest me any library which I can use on both Client side and Server side for communication using web sockets.
I never had experience with WebSocket, but try library cURL (libcurl). It was easiest for me to write clients for HTTP and FTP, using it. It have to help (but curl is useful just for clients, not for server).
If you are talking about sockets, normal sockets that connect on a port and wait for a connection on the server side and that connect to a given address on the client side, then I would recommend the boost asio socket on the c++ side and the standard java socket on the java side.
Just remind yourself of making sure that you transmit the datatype you expect.
Another cool implementation for both, java and c++, is ZeroMQ. I would recommend to take a look at it because it is easy to use and has implemented some really cool communication patterns.
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.