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

  • Home
  • SEARCH
  • 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 6080165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:01:50+00:00 2026-05-23T11:01:50+00:00

i just started writing my first Server/Client code and its a simple chat program

  • 0

i just started writing my first Server/Client code and its a simple chat program , but i dont know how should I run the Code !

there is a .class file named Server Side , and a .class file named clientSide , are they supposed to be in different projects ? how should I run it so they both have a connection together ? thanks already ,following is a part of the codes

public void runServer()
    {
        try {
            server = new ServerSocket();
            while(true)
            {
                try
                {
                    connection = server.accept();
                    try{
                        output = new ObjectOutputStream(connection.getOutputStream()) ;
                        output.flush(); 
                        input = new ObjectInputStream(connection.getInputStream()) ;
                        sendData(message) ;
                        do
                        {
                            try{
                                message = (String) input.readObject() ;
                                System.out.println(message);
                            }catch(Exception e)
                            {
                                e.printStackTrace() ;
                            }
                        }while(!message.equals("end"));
                    }catch(EOFException e)
                    {
                        e.printStackTrace() ;
                    }   
                }catch(IOException e)
                {
                    e.printStackTrace() ;
                }           
                finally {
                    try{
                    output.close();
                    input.close();
                    connection.close() ;
                    }catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                    }
            }
        }catch(Exception e )
        {
            e.printStackTrace(); 
        }
    }

and here’s the clientSide :

public void runClient()
    {
            try{
            connect() ;
            }catch(Exception e)
            {
                e.printStackTrace();
            }
            try{
                output = new ObjectOutputStream(client.getOutputStream()) ;
                output.flush() ;
                input = new ObjectInputStream(client.getInputStream()) ;
            }catch(IOException e)
            {
                e.printStackTrace() ;
            }
            do
            {
                try{
                    message = (String) input.readObject() ;
                    System.out.println(message);
                }catch(Exception e)
                {e.printStackTrace();}
            }while(!message.equals("end")) ;

    }
    public void connect() throws UnknownHostException, IOException
    {
        client = new Socket(InetAddress.getByName(chatServer),12345) ;
    }
  • 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-23T11:01:50+00:00Added an answer on May 23, 2026 at 11:01 am

    First run the server

    java Server

    Then run the client:

    java Client

    But I do not see your server bound to the port 12345. The client will try to connect to the server on the port 12345 because of the statement

    client = new Socket(InetAddress.getByName(chatServer),12345) ;
    

    If the ports do not match, the connection will not be established.

    To bind the server to the port 12345 try this:

    server = new ServerSocket(12345);
    

    instead of the default constructor.

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

Sidebar

Related Questions

I just started learning opengl and writing a first person shooter but I'm getting
I have just installed C# 2008 Express Edition 2008 and started writing code. My
I'm just getting started writing a simple web crawler to get info on links
I have started writing my own WebDAV server class in .NET, and the first
I have just started learning XNA. This is my first program that I am
Getting started on writing my first build script. I dont get the whole dependency
I have just started writing a multilingual application for the very first time. I
I'm just starting to learn Android development and writing my first app. I started
I have just started writing my own JavaScript Framework (just for the learning experience),
I'm looking for a fuzzy date algorithm. I just started writing one and realised

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.