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 7599115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:34:51+00:00 2026-05-30T22:34:51+00:00

Here is the code I have written a server and client. But when i

  • 0

Here is the code

I have written a server and client. But when i run them, (as you can see in the last program), I get the following error:

Whoop s! java.net.BindException: Address already in use 6666
6666 is the port no. i specified.

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

public class processSendHelper
{
    Process p;
    String address;
    int port;
    long msg_data;

    processSendHelper(int pid, int current_round, long address, long msg_data, int port)
    {
        try
        {
            ServerSocket sSoc = new ServerSocket(port);

                Socket inSoc = sSoc.accept();
                msg_Thread msgT = new msg_Thread(inSoc, msg_data);
                msgT.start();
                Thread.sleep(5000);
                sSoc.close();

        }
        catch(Exception e)
        {
            System.out.println("Whoop  s! " + e.toString());
        }

    }

}

/* sends out (or rather just makes available) the provided msg 
 * */
class msg_Thread extends Thread 
{

    Socket threadSoc;
    long msg_data;

    msg_Thread (Socket inSoc, long msg_data) 
    {
        threadSoc = inSoc;
        this.msg_data = msg_data;
    }

    public void run()
    {
        try 
        {
              PrintStream SocOut = new
              PrintStream(threadSoc.getOutputStream());
              SocOut.println(msg_data);
        }

        catch (Exception e)
        {
            System.out.println("Whoops!" + e.toString());
        }

        try 
        {
            threadSoc.close();
        }
        catch (Exception e) 
        {
            System.out.println("Oh no! " +
            e.toString());
        }
    }
}





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


public class processReceiveHelper 
{
        Socket appSoc;
        BufferedReader in;
        String message;
        String host;
        int port;

        processReceiveHelper(String host,int port) 
        {
            try 
            {
                appSoc = new Socket(host,port);
                in = new BufferedReader(new InputStreamReader(appSoc.getInputStream()));
                message = in.readLine();
                System.out.println(message); 
                    /* Tokenizer code comes here 
                     * Alongwith the code for 
                     * updating the process object's
                     * data
                     * */

            }
            catch (Exception e) 
            {
                System.out.println("Died... " +
                e.toString());
            }

        }
}




public class Orchestrator 
{



    public static void main(String[] args)
    {
        processSendHelper psh = new processSendHelper(1, 2, 1237644, 6666, 2002);
        processReceiveHelper prh = new processReceiveHelper("localhost", 2002);

    }
}

EDIT:

I found the problem. The reason was that i was running both the server and client from the same main program.

the following worked:

enter image description here

  • 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-05-30T22:34:52+00:00Added an answer on May 30, 2026 at 10:34 pm

    That means that the port 6666 is already being used. There are two main causes/solutions for this:

    • Some other program is using that port. Solution: Choose a different port.
    • Your old Java program is hanging and still “using” that port. Close all of your hanging Java programs and try again. If that doesn’t solve your problem, choose a different port.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple server - client program with Swing interface using singleton
I have written code for server and client sockets. I have used threads using
I have written a server is java here is the code: public mainClass() {
Here's a snippet of code from a shell script I have written: for src
enter code here I have a table on SQL server 2005 with bigint primary
I have some code here which works perfectly in firefox but not in chrome
I have a client/server application written in C#/.NET 3.5 that I want to do
I Have written a server and a client to implement FTP and if i
Here is the code I have to create an UIAlertView with a textbox. UIAlertView
Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= cmd.exe commandsBuffer ::=

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.