解决方案 »
- 求为什么执行不下去
- java robot类的实现按住按键不放!
- JSplitPane的分割问题
- 如何用java语言编写应用程序模拟excel功能?急!
- 我想回复问题,为什么没有回复一栏?
- tomcat4.1和mysql的连接池错误,搞了半天了,请各位帮忙!
- 我想取33到66之间的一个随机数,请问怎么取呀?在线等,比较急!
- 高手进来接招呀~~~~
- 我什么编译不了java
- 中文 win2000 控制面板->区域设置中一切正常,为何 java 得到的属性 file.encoding 不对?诸位碰到过这种情况吗?
- readObject问题??——为什么接受对象一直不变?
- if条件句中关于else if的问题
如果你出现了那种情况,那么必定有某种程序在连接你本机的TCP端口8888
那么把 public static final int TCP_PORT = 8888;
换成 public static final int TCP_PORT = 9999;
在重启TankServer,估计它就会在s = ss.accept();等待了
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.List;public class TankServer {
private static int ID = 100;
public static final int TCP_PORT = 8888;
public static final int UDP_PORT = 6666;
List<Client> clients = new ArrayList<Client>(); public static void main(String[] args) {
new TankServer().start();
}
public void start() {
ServerSocket ss = null;
try {
ss = new ServerSocket(TCP_PORT);
} catch (IOException e) {
e.printStackTrace();
} while (true) {
Socket s = null;
try {
s = ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
String IP = s.getInetAddress().getHostAddress();
int udpPort = dis.readInt();
Client c = new Client(IP, udpPort);//服务器为什么发这个udp端口给客户端???????????
clients.add(c);
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.writeInt(ID++);
// s.close();
System.out.println("A Client Connect! Addr- "
+ s.getInetAddress() + ":" + s.getPort()
+ "----UDP Port:" + udpPort);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (s != null) {
try {
s.close();
s = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
} private class Client {
String IP;
int udpPort; public Client(String IP, int udpPort) {
this.IP = IP;
this.udpPort = udpPort;
}
}
}
执行上面的命令,看看谁在连8888端口
tcp 127.0.0.1:57025 127.0.0.1:8888 SYN_SENT 3844
这是什么意思 前段时间用8888都没问题
[mysqld.exe](进程名)这段的意思是 mysqlld.exe(PID:1412)的进程在本机所有ip的3306端口监听