-1

I would like to know if we can design a system which will communicate to other system via restful web service as well as via socket communication?

Actually my requirement is that some messages in the form of xml or json will come as input to the system and it will generate response accordingly after performing some business operations. Along with this, a socket communication can also happen with other system. That system may send message in bytearray or different format to this unit.

Now can such unit be developed where it can support both socket communication as well as xml/json?

Swarup Saha
  • 895
  • 2
  • 11
  • 23
  • It is possible, but with downsides [http and websocket using the same port](http://stackoverflow.com/questions/13791050/is-it-possible-to-enable-tcp-http-and-websocket-all-using-the-same-port) – Marsel Novy Oct 13 '16 at 19:30

1 Answers1

0

I would like to know if we can design a system which will communicate to other system via restful web service as well as via socket communication?

Yes, you can have a webSocket connection between two systems and also use REST calls from one to the other. This is actually quite common with systems like node.js/Express.

The webSocket protocol is explicitly designed so that it can run on the same port 80 as regular HTTP requests. It works this way because every webSocket connection actually starts with an HTTP request that has a specific "upgrade" header on it that requests a switch to the webSocket protocol. So, the same receiving server can receive both regular HTTP requests and requests to open a webSocket connection, can detect which is which and can branch in the code accordingly.

See these other relevant references:

How does WebSockets server architecture work?

Why WebSocket can share the 80 port with HTTP "after the handshake"?

What's the difference between WebSocket and plain socket communication?

node js net sockets + websocket without socket.io

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Hi @jfriend00, I want to have a TCP IP plain socket communication as well as restful communication. Kindly let me know if it is possible – Swarup Saha Oct 18 '16 at 07:38
  • @SwarupSaha - Yes, it is possible, between two of your own applications, but a browser does not do a plain TCP/IP socket. It only does Ajax connections and webSocket connections. – jfriend00 Oct 18 '16 at 07:39
  • Thanks for your response.My requirement is that there is a System A which I need to build/design, which can communicate with System B using TCP/IP socket communication (lets say on port 9000) as well as can communicate with system C using rest end point(lets say on port 9001). Can you give me an insight how I can go ahead in building the same in Java? – Swarup Saha Oct 18 '16 at 09:33
  • @SwarupSaha - It sounds like you want us to write the code for you. We don't do that. To communicate with system B, you connect a TCP socket to that system and then you do whatever you want to over that socket. There are hundreds of examples of using TCP from Java on the web. To use rest endpoints with system C, you just make an HTTP request (using one of many different Java libraries that are available for making HTTP requests to a remote server). – jfriend00 Oct 18 '16 at 22:19
  • @SwarupSaha - I've answered your original question several times. If you have more detailed questions about how to accomplish some level of detail in order to implement that, then you should first research the problem yourself, find some relevant examples, write some code, try it yourself and then if you get stuck somewhere, you can ask a new question that shows the code you tried and asks a specific question about where you got stuck. – jfriend00 Oct 18 '16 at 22:20