PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 22, 2022

[FIXED] How to allow connections to a socket only within the same host in java

 October 22, 2022     client-server, java, networking, protocols, sockets     No comments   

Issue

I have a use-case where I want to open a socket and allow connections that are coming only from the same host/machine in which the socket is opened. I don't want to allow any connections from other hosts.

Basically, I want to simulate VM protocol concept of Apache ActiveMQ which works on port 61616.

I want to create something like this:

Socket socket = new Socket("127.0.0.1", 5000)

Is there a way we can do this in Java? Or is there any workaround for this?


Solution

Simply create a ServerSocket that is bound to 127.0.0.1 for IPv4 or ::1 for IPv6. Only clients on the localhost will be able to connect to it.



Answered By - Remy Lebeau
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing