473,419 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

What does the following stack trace means and how can I correct my codes?

108 100+
In this programs i want my client to connect to the server.I run my server,till now it's ok but when I run my client,I get the java.net.ConnectException and the stach trace is something like that :
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at client1.create_client(client1.java:34)
at client1.main(client1.java:17)


client1 class
<code>

import java.net.*;
import java.io.*;
import javax.swing.JTextField;
import java.awt.List;
import java.util.Scanner;
/**
*
* @author vimal
*/
public class client1 {

public static void main(String[] args){

System.out.println("Client test1 successful");
client1 vimal=new client1();
vimal.create_client("localhost",3005);
}

public void create_client(String hostname,int port){


Socket client_socket;
BufferedReader from_server;
PrintWriter to_server;
Scanner user_input=new Scanner(System.in);
String str;


try
{


client_socket=new Socket(hostname,port);

from_server=new BufferedReader(new InputStreamReader(client_socket.getInputStream())) ;
to_server=new PrintWriter(client_socket.getOutputStream(),true);

String client_log;
to_server.println(user_input.nextLine());

while(((str=from_server.readLine() )!=null )){
System.out.println(hostname+" says : "+str);
client_log=user_input.nextLine();

System.out.println("Client says : "+client_log);

to_server.println(client_log);
}

client_socket.close();
from_server.close();
to_server.close();

}
catch(IOException e)
{
e.printStackTrace();
}
}

}
</code>



server1 class
<code>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


import java.net.*;
import java.io.*;
import java.util.Scanner;

/**
*
* @author vimal
*/
public class server1 {


public static void main(String[] args){
server2 vimal=new server2();
vimal.create_server();
}
}

class server2 implements Runnable{
int port;
//String host=null;
PrintWriter to_client=null;
BufferedReader from_client=null;
ServerSocket server=null;
Socket client=null;

server2(int port){
this.port=port;
//this.host=host;
}

server2(){

}


public void create_server(){

Socket client=null;

try
{
server=new ServerSocket(port);
while(true)
{
client=server.accept();
Runnable sr=new server2(3005);
Thread thr=new Thread(sr);
thr.start();

}

}
catch(IOException e)
{
System.err.println(e.getMessage());
}
}


public void run(){
String str;


try{
to_client=new PrintWriter(client.getOutputStream(),true);
from_client=new BufferedReader(new InputStreamReader(client.getInputStream()));

while(((str=from_client.readLine())!=null) && (!(str.equals("quit"))))
{


to_client.println(str);


}

client.close();
to_client.close();
from_client.close();
}
catch(IOException e){
System.err.println(e.getMessage());
}


}
}

</code>


What is wrong wd these codes?

With regards
Sep 13 '10 #1
1 1707
Oralloy
988 Expert 512MB
@phpuser123,

Please use code tags around your programs in the future. It's simple, just place a line the words "code" and "/code" in square brackets above and below your code.

Your problem is that your server refused the IP connection, right?

That means that your server isn't running, it's running on a different port, or there's a firewall in the way, or maybe you got the server's IP address wrong.

Luck!
Sep 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ashish | last post by:
Hello, Is there a way to print stack trace in a c++ application? I would like to do this before asserting in a situation that can't be handled. Thanks, -Ashish
13
by: ranjeet.gupta | last post by:
Dear All What does exactly below code means struct File { void* data; }; typedef struct File File; typedef File* fl;
0
by: Mike Schilling | last post by:
I have some code that calls methods reflectively (the method called and its parameters are determined by text received in a SOAP message, and I construct a map from strings to MethodInfos). The...
8
by: Vishal | last post by:
Hello, I have uploaded my website from VS to my server and unfortunaly there is an error when I visit the website. However the stack trace of the error still points to my local directory. It...
0
by: Greg | last post by:
In my ASP.NET 1.1 Web application I have an HTTP Module that is a "global exception logger." that logs info about otherwise unhandled exceptions. It has logged the following exception 4 times...
2
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
7
by: David T. Ashley | last post by:
Is there any portable method for identifying the caller of a function, its caller, and so on, at runtime, without using a debugger? Clearly, one can dissect the stack frame and trace it back. ...
3
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
2007-01-13 18:40:56,443 ac.server ERROR Error - An unexpected exception for user: admin System.NullReferenceException: Object reference not set to an instance of an obj ect. at...
2
by: mvsmsh | last post by:
Hi , sysproc.snapshot_tbreorg result shows me REORG_STATUS as '4' Does anyone know what does it means ? Regards Myoungsoo
3
by: Zenoba | last post by:
Can someone tell me what does this FOR loop means in C programming? for (;a!=0;a=a>>1) what this for loop does?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.