Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: blocking a network connection

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default blocking a network connection

    hey guys,
    i was wondering is there a way in java to block all incoming/outgoing tcp/ip connection to a computer (i want to build a basic firewall system which as for now just block all connections or allow them at a click of a button)

    thanks!


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: blocking a network connection

    Hello BraveProgrammer and welcome to the Java Programming Forums.

    Do you know which ports you wish to block or do you want to block every port?

    Read up on Java Networking - Networking Basics (The Java™ Tutorials > Custom Networking > Overview of Networking)

    I think you will need to write something that listens on a certain port and then denies connection.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: blocking a network connection

    hey, thanks, glad to be here

    actually for this moment i would like to be able to block the entire connection so ill rather block all the ports instead of listening to each and every port..

    ill defenatly read on Java Networking but i persume it will explain about creating and blocking connections specified by certain ports, do u know a way to generalize it and block it all?

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: blocking a network connection

    Quote Originally Posted by BraveProgrammer View Post
    hey, thanks, glad to be here

    actually for this moment i would like to be able to block the entire connection so ill rather block all the ports instead of listening to each and every port..

    ill defenatly read on Java Networking but i persume it will explain about creating and blocking connections specified by certain ports, do u know a way to generalize it and block it all?
    Hmm.. I'm not too sure how you would go about blocking every port. When I have done something similar in the past, the application was listening on a certain port and rejected the connection that way.

    If a port isn't open, no one will be able to connect to it anyway.

    Hopefully someone else can shed some light on this...
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: blocking a network connection

    I believe most operating systems prevent opening multiple connections using the same port (linux does, and I believe Windows and MacOS do too). You could try opening connections to every port to prevent any other connections to that port, but you will run into a few problems:

    1. You have no way of knowing when another application wants to use that port. This is fine if you want to just block that port, but you can't release the port without either random guessing or making every application use some API through your program to request access to that port (this just won't happen)
    2. This assumes your application has unhindered access to every single port 0-0xffff. This will never be the case. Address 0-1024 are almost always reserved by the OS, and either will disallow opening them or will require super-user/administrator rights. This also means that your application must connect to the port before any other application connects to it.
    3. I don't think there is a way for you to forcibly terminate a connection if it already exists (at least not in pure Java)

    If you want to stop all port communication, simply disable your network card.

Similar Threads

  1. Partial messages problem with Java non-blocking socket communication
    By perl0101 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: July 28th, 2010, 03:38 PM
  2. How can I reduce network utilization?
    By Drakenmul in forum Java Networking
    Replies: 0
    Last Post: June 15th, 2010, 05:58 AM
  3. Network problem
    By subash in forum Java Networking
    Replies: 0
    Last Post: March 9th, 2010, 06:07 AM
  4. callback functions? non-blocking socket help
    By Tomas in forum Java Networking
    Replies: 0
    Last Post: September 12th, 2009, 06:46 PM
  5. network scanner
    By vivek494818 in forum Java Networking
    Replies: 0
    Last Post: August 17th, 2009, 11:07 PM

Tags for this Thread