package com.java;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
public class Server {
/**
* @param args
*/
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(7777);
System.out.println("·þÎñÆ÷¶ËÔÚ7777¶Ë¿Ú¼àÌý¡¡");
Socket s = ss.accept();
System.out.println("ÒÑÓпͻ§¶ËÁ¬½Ó¹ýÀ´£¬¿ªÊ¼½øÐÐͨѶ¡¡");
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
PrintWriter pw = new PrintWriter(out);
System.out.println("ÕýÔÚÏò¿Í»§¶Ë·¢ËÍÏûÏ¢¡¡");
pw.write("¿Í»§¶Ë£¬ÄãºÃ£¬ÕâÀïÊÇ·þÎñÆ÷¶Ë¡£\r\n");
pw.flush();
System.out.println("Ïò¿Í»§¶Ë·¢ËÍÏûÏ¢Íê³É¡£");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String response = br.readLine();
System.out.println("======ÏÂÃæÊÇ¿Í»§¶Ë·¢À´µÄÏûÏ¢======");
System.out.println(response);
System.out.println("================================");
br.close();
pw.close();
s.close();
ss.close();
} catch (UnknownHostException e) {
System.out.println("ÎÞ·¨ÕÒµ½ÏàÓ¦µÄ»úÆ÷£¬´íÎóÐÅÏ¢£º" + e.getMessage());
} catch (IOException e) {
System.out.println("Êý¾Ý´«Êä³öÏÖÒì³££º" + e.getMessage());
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
public class Server {
/**
* @param args
*/
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(7777);
System.out.println("·þÎñÆ÷¶ËÔÚ7777¶Ë¿Ú¼àÌý¡¡");
Socket s = ss.accept();
System.out.println("ÒÑÓпͻ§¶ËÁ¬½Ó¹ýÀ´£¬¿ªÊ¼½øÐÐͨѶ¡¡");
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
PrintWriter pw = new PrintWriter(out);
System.out.println("ÕýÔÚÏò¿Í»§¶Ë·¢ËÍÏûÏ¢¡¡");
pw.write("¿Í»§¶Ë£¬ÄãºÃ£¬ÕâÀïÊÇ·þÎñÆ÷¶Ë¡£\r\n");
pw.flush();
System.out.println("Ïò¿Í»§¶Ë·¢ËÍÏûÏ¢Íê³É¡£");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String response = br.readLine();
System.out.println("======ÏÂÃæÊÇ¿Í»§¶Ë·¢À´µÄÏûÏ¢======");
System.out.println(response);
System.out.println("================================");
br.close();
pw.close();
s.close();
ss.close();
} catch (UnknownHostException e) {
System.out.println("ÎÞ·¨ÕÒµ½ÏàÓ¦µÄ»úÆ÷£¬´íÎóÐÅÏ¢£º" + e.getMessage());
} catch (IOException e) {
System.out.println("Êý¾Ý´«Êä³öÏÖÒì³££º" + e.getMessage());
}
}
}