Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:42:53+00:00 2026-06-01T12:42:53+00:00

I have a java server which is using TCP and sockets to connect to

  • 0

I have a java server which is using TCP and sockets to connect to an Android application (the client) and sends strings (currently taken in from a scanner object) which are then displayed as notifications by the client.

heres the Server code without all the imports.

public class Server {

// define our Main method
public static void main(String[] args) throws IOException {
    // set up our Server Socket, set to null for the moment.
    ServerSocket serverSocket = null;
             boolean isConnected = false;

    // Lets try and instantiate our server and define a port number .
    try {
        serverSocket = new ServerSocket(6789);
                isConnected = true;
        System.out.println("***  I am the Server  ***\n");
        // make sure to always catch any exceptions that may occur.
    } catch (IOException e) {
        // always print error to "System.err"
        System.err.println("Could not listen on port: 6789.");
        System.exit(1);
    }

    // We always want to check for connection from Clients, so lets define
    // a for ever loop.
    for (;;) {
        // define a local client socket
        Socket clientSocket = null;
        // lets see if there are any connections and if so, accept it.
        try {
            clientSocket = serverSocket.accept();
            // don't forget to catch your exceptions
        } catch (IOException e) {
            System.err.println("Accept failed.");
            System.exit(1);
        }

        // Prepare the input & output streams via the client socket.

        // fancy way of saying we want to be able to read and write data to 
        // the client socket that is connected.

        BufferedReader inFromClient = new BufferedReader(new InputStreamReader(
                clientSocket.getInputStream()));
        PrintWriter outToClient = new PrintWriter(clientSocket.getOutputStream(),
                true);

              while (isConnected) { 
        // read a sentence from client
        String hiFromClient = inFromClient.readLine();


                    // Set up the logging system and timestamp and log message.

                     Calendar currentDate = Calendar.getInstance();
         SimpleDateFormat formatter= 
         new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss");
         String dateNow = formatter.format(currentDate.getTime());


        try{
            // Create file 
            File fstream = new File("log.txt");
                        FileWriter out = new FileWriter(fstream);
                               out.write(hiFromClient + " " + dateNow);

                               //Close the output stream
                               out.close();
                    } catch (Exception e){//Catch exception if any
                           System.err.println("Error: " + e.getMessage());
                    }


        // Print the client sentence to the screen
        System.out.println("The Client said: "+hiFromClient);

        // Reply to the client

                    Scanner scanner = new Scanner(System.in);
                    String sentence = scanner.nextLine();

        outToClient.println(sentence );
                    System.out.println("The Server said: " + sentence);

        }     
        // always remember to close all connections.


        inFromClient.close(); // the reader
        outToClient.close(); // the writer
        clientSocket.close(); // and the client socket
    }
}}

Growl uses port 23053 for notification forwarding. What i am hoping to do is to listen in on 23053 and send anything in from that as a string to the client connected at 6789. Sadly Growl binds the port number so a new Socket connection cant be made.

Any one have any ideas on how i could get notifications from the port number growl uses or even just use growl as the server for the client itself (the client’s code is very similar to the servers by the way just using Socket instead of ServerSocket)

Any help on this would be greatly appreciated, its wrecking my brain

All the best,

Patrick.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:42:55+00:00Added an answer on June 1, 2026 at 12:42 pm

    There is a round-about way you could do it. If you are desperate, read on:

    Growl can forward any notifications it receives to another machine running Growl (configured on the Network tab). Growl uses the GNTP protocol (a TCP-based protocol: http://www.growlforwindows.com/gfw/help/gntp.aspx) to forward the messages. The trick is that that ‘other machine running Growl’ doesnt have to really be another machine OR running Growl per se, it just needs to appear to Growl that it is. Growl (on the Mac, which is what I assume you are using) will automatically detect any other machines on the network running Growl (using Bonjour and looking for the _gntp._tcp service name), so if your server advertises itself as supporting the GNTP protocol, Growl should show it in the list of available destinations. (Growl for Windows also lets you manually add a hostname/port to forward to, but I dont believe the Mac version currently allows that).

    So then you could configure Growl to forward notifications to your server using its already-built-in capabilities. You would have to implement code in your server to receive the GNTP packets (the format is very similar to HTTP headers) and parse them. Then you could forward the notifications using your current server code.

    Still with me? I did say it was round-about, but it is not only technically possible, but I have built a Growl-impersonating daemon before so that I could have notifications forwarded from Growl to my custom code. Not suggesting it as the best idea, but just an alternative since you asked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java Client which sends UTF-8 strings to a C# TCP-Server, I'm
I have a Java client that connects to a C++ server using TCP Sockets
I have a client Server application which communicate using objects. when I send only
I have a client-server application written in Java using CORBA for the communication. The
I have created a java server, which takes screenshots, resizes them, and sends them
We have a java application which run as server running on a remote windows
I have a Java based web-application using Java Server Faces and Facelets. I am
I have the following algorithm implemented in Java which uses TCP/IP: -Client request a
I am trying to tcp connect to a server machine in java, by using
We have a small java based server (a simple app which fetches data using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.