package csdn; import java.io.IOException; import java.net.*; public class Server { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ServerSocket ss = null; try { System.out.println("Server starting...."); ss = new ServerSocket(1983,1);
import java.io.IOException;
import java.net.*;
public class Server { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ServerSocket ss = null;
try {
System.out.println("Server starting....");
ss = new ServerSocket(1983,1);
int conNum =0;
while(conNum<2){//这里控制
conNum++;
Socket sget= ss.accept();
System.out.println(""+sget.getInetAddress());
System.out.println(""+sget.getPort());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}package csdn;
import java.io.IOException;
import java.net.*;
public class Client { /**
* @param args
*/
public Client(){
System.out.println("connect");
try {
Socket s = new Socket (InetAddress.getLocalHost(),1983);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Client();new Client();new Client();new Client();new Client();
}}