Problem

Problem

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

public class EchoClient { public static void main(String[] args) throws IOException {

    Socket echoSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;

    try 
    {
        echoSocket = new Socket("sunil-PC", 7);
        out = new PrintWriter(echoSocket.getOutputStream(),true);
        in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
    }
    catch (UnknownHostException e) 
    {
        System.err.println("Don't know about host: sunil-PC.");
        System.exit(1);
    } 
    catch (IOException e) 
    {
        System.err.println("Couldn't get I/O for " + "the connection to: sunil-PC."+ e);
        System.exit(1);
    }

    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
    String userInput;

    while ((userInput = stdIn.readLine()) != null) 
    {
        out.println(userInput);
        System.out.println("echo: " + in.readLine());
    }

    out.close();
    in.close();
    stdIn.close();
    echoSocket.close();
}

}

this is my code, compiled with no errors, but when running giving "java.net.connectexception connection refused: connect"

View Answers

January 9, 2012 at 4:39 PM

Check that the server (something like EchoServer) is up and running.









Related Tutorials/Questions & Answers:
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
problem in validation
problem in validation  sir/madam, i m using struts-1.3.10. i m getting a problem my properties file is not found.... while i hav configuired it in struts-config.xml file, likeADS_TO_REPLACE_1 thanks n regards himanshu
Advertisements
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other
Oracle9i Problem
Oracle9i Problem  Hi I have a problem in Oracle9i .I have... the table what i created .But after closing the SQL+ ,the problem started.When i... .....;.it is saying no rows are selected.Why the problem arised in not getting the data that i
problem with session.invalidate()
problem with session.invalidate()  i stuck by a line with "session.invalidate()", after user logout also by pressing the back button of the browser user is still able to navigate to his home page and able to view the session
JScrollBar Problem...
JScrollBar Problem...  Hello Sir/mam, Can i know how to use JScrollBar to JFrame without adding any JPanel to it.. i want to add JScrollBar Directly to JFrame... Please Provide me Simple Example so i can understand
problem on php
problem on php   l have five tables and build them as forms and link between them php and database and i want to build query between them plz help me soon   PHP MySQL Tutorials
URL problem
URL problem  Hi. I have created a webpage for my project website. in that i have used frameset to split the page. Now if i click any link in the page its navigating to the another page. but the problem is here in the url its
Is AI a problem?
Is AI a problem?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Is AI a problem? Try... "Is AI a problem?". Also tell me which is the good training courses
Skyline Problem
is the line tracing the largest y value from any rectangle in S The Problem: Write.... Your method should solve the problem three different ways; each solution
Problem in Array
Problem in Array  Hi, Can you help me with this problem? Run a program that check if the input string contains equal number of A's and B's. Hoping for your answer.Thank you.   Here is an example that check
problem
Problem
Problem
problem
problem
PROBLEM IDENTIFICATION
PROBLEM IDENTIFICATION  class MOrders { int nooforders; // Data members of the class public int getorder() { nooforders = 500; } public void displayorders() { System.out.println("The number of orders to be delivered
problem in coding
problem in coding  i have a following code which display the contents of the text file but not other program like java or any c program is there any handler to open the program files other than Filereader. FileReader fr = new
problem in html
problem in html  i want that my custmer can upload file or video on my website so plz help and send me the code which i can paste on my web site so people can upload their video and img and plz send the html code becaz my web
HttpSession problem :(
HttpSession problem :(  i want to ask that do i need to define httpsession in every servlet or jsp in my web application? if yes, then on which servlet? the very first one like my welcome page which comes after login page
Problem in enctype=
Problem in enctype=  im using a page which is in JSP. i have some text boxes and one upload button. i want to load the file itself when i click.... but the problem is the uploaded file is not stored in the prefered folder. i printed
php problem
php problem  Hello!! I have a problem ,i want to display the data of a single row in my database,this is the code: <?php</p> include 'connectMySql.php'; $username=$row['username']; if(! $conn ) { die('Could
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My database is in mysql.Plsssss help me... Thanks
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My database is in mysql.Plsssss help me... Thanks
Problem with arraylist
Problem with arraylist  I am currently working on a java project and there is an if loop within the for loop.... for(int i = 1;i < iterationsNo.... It seems that problem
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My database is in mysql.Plsssss help me... Thanks
PROBLEM IN EXECUTION
PROBLEM IN EXECUTION  class R { private int x; private int y; void getdata(int x1,int x2) { x=x1; y=y1; } void displaydata() { system.out.println(x+"\t"+y
uploading problem
(); } } } } %> my problem...: firstly.... then problem solved... bt real problem is when i upload files fusing mozilla browser...it shows like this... problem loading page.. The connection was reset
logout problem
logout problem  I am stuck in my application --- hope anyone can take me out of this... the problem is -- when i logout , the user goes... he has come from .. please get me out of this problem thanks.   Use
Servlet problem
Servlet problem  Hello, I am very shocked about this mysterious problem from last three month and now i hope rose india developers... connectivity code it works but problem is with servlet page. My servlet code
problem with response.getOutputStrem()
problem with response.getOutputStrem()  <%@page import="javax.servlet.*, javax.servlet.http.*,java.io.*,java.util.*,com.kit.log.*,com.kit.db.util.*"%> <%@include file="sessioncheck.jsp"%> <
problem in database
problem in database   thanks for web site. I want change this code to insert data into PostgreSql database using jsp,servlets. but i getting output "Record has been inserted", 1.no data in the table(sample) public
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text field........at that time action is perform and data is retriev from data base and get assign to other field on that form........ when data is assign to other
solve this problem
in table please tell me the solution for thid problem import java.io.*; import
jdbc problem
jdbc problem   hi my name is mohit...i am making a project in java swings....pls help me how to check that the username and password are correct...the user inputs the username and password and then i want to match the username
problem of confirmation
problem of confirmation  sir, I tried ur code but when i click on cancel it still submits I dont need to pass id as record is already diaplayed using ajax and i used it in delete button like this <form method="post" id
in php installation problem ?
in php installation problem ?   php installation in 7th step did not display y/n dialog box how to solve the problem
problem in servlet program
problem in servlet program  Dear Sir, I have a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
problem in programming - JSP-Servlet
problem in programming  Hi! I am new with jsp. I am facing a problem in programming to calculate the time interval between login time and logout time of user
resolution problem in java
resolution problem in java  I designed project in java in my PC when run the same project in some other PC i can't fully view my java forms.Some said that it is resolution problem
problem i coding
problem i coding  i have a problem in coding a combobox containing a number of *.java program on click one of them that program should compile and run and display the result in other window
Problem of Import JWorkbook
Problem of Import JWorkbook  Hi... i can't use the jworkbook in my project.what types of library files in import
Struts 2 problem - Struts
Struts 2 problem  Hello I have a very strange problem. I have an application that we developed in JAVA and the application works ok in Windows... seemed to worked fine, until the user reported to us a problem. After doing
problem in swing-awt
problem in swing-awt  I am doing project in core java and i am facing one problem. I have to add command prompt(terminal) to the fream at bottom but not getting the solution. So please help me. thanks and regards, Aakash

Ads