network_socket_properties.htm
This example shows how to use socket's properties and also use a constructor to get returns form a remote class.
 

//import java.lang.reflect.*;
import java.io.*;
import java.net.*; // for datagram
public class Test_this {
static public void main( String[] args )throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//my name is mukherjee sanam
System.out.print("Type name: ");
String str ="";
System.out.print(str.toString());
str = br.readLine();
if((str !="") | (str != null)){
team_this pt = new team_this(12, 23,"baba","no");
System.out.println(pt);
pt.method_parse(str);
} } }
class team_this {
public int player_id;;
public int player_uniform;
public String player_name;
public String active;
public boolean subs;
public team_this( int p_id, int p_uniform, String p_name, String state)
{
System.out.println("theam_this class constructor evoked" );
this.player_id = p_id;
this.player_name= p_name;
this.player_uniform = p_uniform;
this.active =state;
}
public String toString()
{
System.out.println("---this pointer projects ---" );
final String separator = java.lang.System.getProperty("line.separator");
String str = "player name : " + player_name + separator+ " player id : " + player_id + separator +" player_uniform :" + player_uniform + separator;
if(active =="yes"){ str += " active " ;}
else { str += " sub " ;}
return str;
}

public void method_parse(String str)throws IOException
{
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
team_this pt = new team_this(player_id, player_uniform,player_name,active);
System.out.println("Method processing echo from the socket at the server end");
try {
echoSocket = new Socket(str, 80);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream()));
System.out.println("Welocme to : " + str + " at local port no : " + echoSocket.getLocalPort());
System.out.println("Welocme to : " + str + " at port no : " + echoSocket.getPort());
System.out.println("Welocme to : " + str + " sent buffer size : " + echoSocket.getSendBufferSize());
System.out.println("Welocme to : " + str + " received buffer size : " + echoSocket.getReceiveBufferSize());
System.out.println("Welocme to : " + str + " address : " + echoSocket.getInetAddress());
System.out.println("Welocme to : " + str + " address remote: " + echoSocket.getRemoteSocketAddress());

System.out.println("print object at server : " + pt);
} catch (UnknownHostException e) {
System.err.println("Don't know about host: ." +str);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for " + "the connection to: ." +str);
System.exit(1);
}
out.close();
in.close();
echoSocket.close();
}

}