各位大虾,小弟正在学习socket,写了一个简单的程序,但是Server端运行不起来,代码如下,请牛人帮忙!
小弟这厢有礼了
import java.io.*;
import java.net.*;public class Server { ServerSocket ss = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
new Server().start();
}
public void start() {
try {
ss = new ServerSocket(8888);
//started = true;
} catch (BindException e) {
System.out.println("端口使用中,请关闭相关程序,并重新启动服务器!");
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
}
}
public void send(String str) {
}
}
小弟这厢有礼了
import java.io.*;
import java.net.*;public class Server { ServerSocket ss = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
new Server().start();
}
public void start() {
try {
ss = new ServerSocket(8888);
//started = true;
} catch (BindException e) {
System.out.println("端口使用中,请关闭相关程序,并重新启动服务器!");
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
}
}
public void send(String str) {
}
}
ss = new ServerSocket(8888);
started = true;
Socket socket = ss.accept();
while(started)
{
new Thread(new Client(socket)).start();//启动一个线程
}//started = true;
} catch (BindException e) {
System.out.println("端口使用中,请关闭相关程序,并重新启动服务器!");
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
}
} private class Client implements Runnable
{
Socket soc; public Client(Socket soc)
{
this.soc = soc;
} public void run()
{}
}