but, the problem is that i get a java.net.ConnectException: Connection refused error.
The code i have written is :
Expand|Select|Wrap|Line Numbers
- //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);
- }
- }
- }