i am writing an client application that connects to the server and then sends data to server.
but, the problem is that i get a java.net.Connec tException: Connection refused error.
The code i have written is :
please let me know wat could be the problem.
but, the problem is that i get a java.net.Connec tException: Connection refused error.
The code i have written is :
Code:
//package bdn;
/* The java.net package contains the basics needed for network operations. */
import java.net.*;
/* The java.io package contains the basics needed for IO operations. */
import java.io.*;
/** The SocketClient class is a simple example of a TCP/IP Socket Client.
*
*/
public class SocketClient {
public static void main(String[] args) {
/** Define a host server */
//find the ip address by ping cmd in unix
String host = "211.65.63.147";
/** Define a port */
int port = 8080;
StringBuffer instr = new StringBuffer();
String TimeStamp;
System.out.println("SocketClient initialized");
try {
/** Obtain an address object of the server */
InetAddress address = InetAddress.getByName(host);
/** Establish a socket connetion */
Socket connection = new Socket(address, port);
/** Instantiate a BufferedOutputStream object */
BufferedOutputStream bos = new BufferedOutputStream(connection.
getOutputStream());
/** Instantiate an OutputStreamWriter object with the optional character
* encoding.
*/
OutputStreamWriter osw = new OutputStreamWriter(bos, "US-ASCII");
}
catch (Exception g) {
System.out.println("Exception: " + g);
}
}
}
Comment