Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

socket programming with firewall issue

Posted on 2007-10-18
8
Medium Priority
?
949 Views
Last Modified: 2012-08-14
hi,

i am trying to run my little socket program with the server in a remote machine, for some reason if i disable the fire wall in the remore machine, everything works, but if the firewall is on, it doesn't.  is there an .exe i need to add to the program lists in the firewall?  i have already added my local machine's ip addr to the firewall.

import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) {
      
      String hostname = "64.139.12.29";
      int port = 6789;

      // declaration section:
      // clientSocket: our client socket
      // os: output stream
      // is: input stream
      
        Socket clientSocket = null;  
        DataOutputStream os = null;
        BufferedReader is = null;
      
      // Initialization section:
      // Try to open a socket on the given port
      // Try to open input and output streams
      
        try {
            clientSocket = new Socket(hostname, port);
            os = new DataOutputStream(clientSocket.getOutputStream());
            is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: " + hostname);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: " + hostname);
        }
      
      // If everything has been initialized then we want to write some data
      // to the socket we have opened a connection to on the given port
      
      if (clientSocket == null || os == null || is == null) {
          System.err.println( "Something is wrong. One variable is null." );
          return;
      }

      try {
          while ( true ) {
            System.out.print( "Enter an integer (0 to stop connection, -1 to stop server): " );
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String keyboardInput = br.readLine();
            os.writeBytes( keyboardInput + "\n" );

            int n = Integer.parseInt( keyboardInput );
            if ( n == 0 || n == -1 ) {
                break;
            }
            
            String responseLine = is.readLine();
            System.out.println("Server returns its square as: " + responseLine);
          }
          
          // clean up:
          // close the output stream
          // close the input stream
          // close the socket
          
          os.close();
          is.close();
          clientSocket.close();  
      } catch (UnknownHostException e) {
          System.err.println("Trying to connect to unknown host: " + e);
      } catch (IOException e) {
          System.err.println("IOException:  " + e);
      }
    }          
}
0
Comment
Question by:mmingfeilam
  • 5
  • 2
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 20102854
All that entirely depends on the firewall you're using. You need to give permissions for the use of that port and maybe java.exe itself
0
 

Author Comment

by:mmingfeilam
ID: 20103659
how do you set the permission for a port for zone alarm free?   also, it looks like the remote server is able to receive the data from my local client, it's just that my local client is not able to get something back from the remote server unless the firewall on the remote server is disabled.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20103726
>>how do you set the permission for a port for zone alarm free?

Well you set it per program actually not per port. What port is your client listening on?
0
Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

 

Author Comment

by:mmingfeilam
ID: 20103898
port 2972.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20104127
netstat -p tcp -an

Should reveal the connection on that port. If it doesn't, you have a problem
0
 
LVL 92

Expert Comment

by:objects
ID: 20104996
you'll need to open up the port
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 750 total points
ID: 20107254
>>you'll need to open up the port

As i've already mentioned, that's not how that firewall works
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20808573
:-)
0

Featured Post

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question