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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:41:15+00:00 2026-05-15T20:41:15+00:00

My prof. gave me this TCP/UDP example and he said it worked for him.

  • 0

My prof. gave me this TCP/UDP example and he said it worked for him. However when I go to compile I get a deprecated API error saying readLine is not in use anymore…

How do I handle this?

Code:

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

public class Server{

    static  Socket clientSocket = null;
    static  ServerSocket serverSocket = null;

    // This chat server can accept up to 10 clients' connections

    static  clientThread t[] = new clientThread[10];

    public static void main(String args[]) {

    // The default port

    int port_number=2222;

    if (args.length < 1)
        {
        System.out.println("Usage: java MultiThreadChatServer \n"+
                   "Now using port number="+port_number);
        } else {
        port_number=Integer.valueOf(args[0]).intValue();
        }

        try {
        serverSocket = new ServerSocket(port_number);
        }
        catch (IOException e)
        {System.out.println(e);}

    while(true){
        try {
        clientSocket = serverSocket.accept();
        for(int i=0; i<=9; i++){
            if(t[i]==null)
            {
                (t[i] = new clientThread(clientSocket,t)).start();
                break;
            }
        }
        }
        catch (IOException e) {
        System.out.println(e);}
    }
    }
}

class clientThread extends Thread{

    DataInputStream is = null;
    PrintStream os = null;
    Socket clientSocket = null;
    clientThread t[];

    public clientThread(Socket clientSocket, clientThread[] t){
    this.clientSocket=clientSocket;
        this.t=t;
    }

    public void run()
    {
    String line;
        String name;
    try{
        is = new DataInputStream(clientSocket.getInputStream());
        os = new PrintStream(clientSocket.getOutputStream());
        os.println("Enter your name.");
        name = is.readLine();
        os.println("Hello "+name+" to our chat room.\nTo leave enter /quit in a new line");
        for(int i=0; i<=9; i++)
        if (t[i]!=null && t[i]!=this)
            t[i].os.println("*** A new user "+name+" entered the chat room !!! ***" );
        while (true) {
        line = is.readLine();
                if(line.startsWith("/quit")) break;
        for(int i=0; i<=9; i++)
            if (t[i]!=null)  t[i].os.println("<"+name+"> "+line);
        }
        for(int i=0; i<=9; i++)
        if (t[i]!=null && t[i]!=this)
            t[i].os.println("*** The user "+name+" is leaving the chat room !!! ***" );

        os.println("*** Bye "+name+" ***");

        for(int i=0; i<=9; i++)
        if (t[i]==this) t[i]=null;

        is.close();
        os.close();
        clientSocket.close();
    }
    catch(IOException e){};
    }
}

The same thing happens in the Client class.

  • 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-15T20:41:15+00:00Added an answer on May 15, 2026 at 8:41 pm

    I’m assuming that you would like to know what you should be using instead? The Java API document states that you should use BufferedReader instead and they even give you the codez!

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

Sidebar

Related Questions

I'm trying to get my prof's overengineered C++ code to compile. This is the
It seems like I always get this error on one of my scripts: /Users/amosng/.rvm/gems/ruby-1.9.3-p194/gems/ruby-prof-0.11.2/lib/ruby-prof/profile.rb:25:
This was an example from our prof and my HTML is rusty so I'm
Recently I came across this video on Programming Paradigms and the prof. used terms
Not too long ago my Delphi 6 prof has worked well (1-2 months?). But
Our professor gave us this assignment, where we have a .txt file with the
In one of my prof slides on ploymorphism, I see this piece of code
I'm trying to follow the prof's example of creating an editable table on double
I have this HTML: <?php if(!empty($_GET['pID'])) $the_pID = mysql_real_escape_string($_GET['pID']); #echo $the_pID; ?> <form action=inc/q/prof.php?pID=<?php
if ($row['active'] == 1) echo '<a href=prof?id=$id>'.htmlspecialchars($row['username']).'</a>'; else echo htmlspecialchars($row['username']); Could I write this

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.