public class Ace
{
public static void main(String[] arg)
{
new Abc();
}
}
class Abc extends Frame
{
private static final long serialVersionUID = 1L;
public Abc(){
this.setSize(600, 600);
this.setLocation(50, 50);
this.setVisible(true);
TextArea text = new TextArea("default words");
text.setSize(300, 300);
this.add(text);
this.socket();
}
void socket()
{
try{
Socket socket = new Socket("127.0.0.1",8798);
BufferedWriter buffer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
buffer.write("I love you");
buffer.close();
}catch(UnknownHostException e){
e.printStackTrace();
System.out.println(e.getMessage());
}catch(IOException e){
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(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 Abc.socket(Ace.java:33)
at Abc.<init>(Ace.java:28)
at Ace.main(Ace.java:14)