How can I create my custom socket in java, to send information directly from the socket, for example, the socket I can see the client IP, but what if, instead of the IP I wanted to send the user name that is connected, or X other information, how about it?
Server:
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(55555);
Socket client = ss.accept();
System.out.println(client.getInetAddress().getHostAddress());
ss.close();
client.close();
}
}
Client:
public class Client {
public static void main(String[] args) throws UnknownHostException, IOException {
Socket s = new Socket("195.168.50.7", 55555);
}
}
Result:
195.168.50.155
My question:
MyServer:
public class MyServer {
public static void main(String[] args) throws IOException {
MyServerSocket ss = new MyServerSocket(55555);
MySocket client = ss.accept();
System.out.println(client.getMyInformationX());
ss.close();
client.close();
}
}
MyClient:
public class MyClient {
public static void main(String[] args) throws UnknownHostException, IOException {
MySocket s = new MySocket("192.168.50.7", 55555);
}
}
My result:
myInformationX
EDIT:
More details: I wonder how I can send directly from the socket instantiates the user who is logged on the machine, without using outputstream or inputstream in the same way that I can get the IP without using outputstream or inputstream.
The user opens the application, the application creates the mysocket, the mysocket communicates with myServidor the diremante myServer the mysocket return the user who is logged in.
Something like:
mySocket.getUserLogged ()
Reader/Writer, but for now it isn't clear what you exactly want.