package netlearn;import java.net.*;
import java.io.*;public class SimpleServer {
public static void main(String args[]) {
ServerSocket s = null;
Socket s1;
String sendString = "Hello Net World!";
OutputStream s1out;
DataOutputStream dos;// Register your service on port 5432
try {
s = new ServerSocket(5432);
} catch (IOException e) { }// Run the listen/accept loop forever
while (true) {
try {
// Wait here and listen for a connection
s1=s.accept();// Get a communication stream for soocket
s1out = s1.getOutputStream();
dos = new DataOutputStream (s1out);// Send your string! (UTF provides machine-independent format)
dos.writeUTF(sendString);// Close the connection, but not the server socket
s1out.close();
s1.close();
} catch (IOException e) { }
}
}
}
import java.io.*;public class SimpleServer {
public static void main(String args[]) {
ServerSocket s = null;
Socket s1;
String sendString = "Hello Net World!";
OutputStream s1out;
DataOutputStream dos;// Register your service on port 5432
try {
s = new ServerSocket(5432);
} catch (IOException e) { }// Run the listen/accept loop forever
while (true) {
try {
// Wait here and listen for a connection
s1=s.accept();// Get a communication stream for soocket
s1out = s1.getOutputStream();
dos = new DataOutputStream (s1out);// Send your string! (UTF provides machine-independent format)
dos.writeUTF(sendString);// Close the connection, but not the server socket
s1out.close();
s1.close();
} catch (IOException e) { }
}
}
}
import java.io.*;public class SimpleClient {
public static void main(String args[]) throws IOException {
int c;
Socket s1;
InputStream s1In;
DataInputStream dis;// Open your connection to myserver, at port 5432
s1 = new Socket("202.114.194.130",80);// Get an input file handle from the socket and read the input
s1In = s1.getInputStream();
dis = new DataInputStream(s1In); String st = new String (dis.readUTF());
System.out.println(st);// When done, just close the connection and exit
s1In.close();
s1.close();
}
}