public class Client {
public static void main(String[] args){
try{
ServerSocket ss = new ServerSocket(6666);
Socket s = ss.accept();
DataInputStream din = new DataInputStream(s.getInputStream());
String str = din.readUTF();
System.out.println("Message received: " + str);
ss.close();
}catch(Exception e){
System.out.println(e);
}
}
}
public class Server {
public static void main(String[] args){
int port = 6666;
String ipAdress = "localhost";
try{
Socket s = new Socket(ipAdress, port);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){
System.out.println(e);
}
}
}
public class Client {
public static void main(String[] args){
try{
ServerSocket ss = new ServerSocket(6666);
Socket s = ss.accept();
DataInputStream din = new DataInputStream(s.getInputStream());
String str = din.readUTF();
System.out.println("Message received: " + str);
ss.close();
}catch(Exception e){
System.out.println(e);
}
}
}
public class Server {
public static void main(String[] args){
int port = 6666;
String ipAdress = "localhost";
try{
Socket s = new Socket(ipAdress, port);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){
System.out.println(e);
}
}
}
Du måste vara medlem för att kunna kommentera