看了下nutz里边关于socket的代码,试着写了下:
服务端
public void start(){
int port = 10086;
Map<String, SocketAction> actions = new HashMap<String, SocketAction>();
actions.put("T1001", new T1001());
int poolSize = 10;
Sockets.localListenByLine(port, actions, poolSize);
}
SocketAction的实现:
public class T1001 implements SocketAction {
@Override
public void run(SocketContext context) {
System.out.println("T1001"); //这一句进不来
}
}
启动:
@Test
public void start() throws Exception {
new MainModule().start();
}
调用:
@Test
public void testListen(){
System.out.println(Sockets.sendText("127.0.0.1",10086, "admin"));
}
服务端日志:
17-9-21 17:14:23.703 INFO [main] Select SystemLog as Nutz.Log implement
17-9-21 17:14:23.712 INFO [main] Local socket is up at :10086 with 1 action ready
17-9-21 17:14:23.720 DEBUG [main] Waiting for new socket
17-9-21 17:14:38.30 DEBUG [main] accept a new socket, create new SocketAtom to handle it ...
17-9-21 17:14:38.31 DEBUG [main] Waiting for new socket
17-9-21 17:14:38.31 DEBUG [pool-1-thread-1] connect with '/127.0.0.1:58407'
客户端日志:
17-9-21 17:14:38.20 INFO [main] Select SystemLog as Nutz.Log implement
现在问题是不进我自己的SocketAction实现,这个要怎么写?还有没有其他什么漏掉的东西?