2
|
1 package rep;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetSocketAddress;
|
|
5 import java.nio.channels.SocketChannel;
|
|
6
|
|
7 public class SMConnector {
|
|
8 private SocketChannel sessionchannel;
|
|
9
|
|
10 public void connectSession(String host) {
|
|
11 int port = 8765;
|
|
12 //int port = Integer.parseInt(args[2]);
|
|
13 InetSocketAddress addr = new InetSocketAddress(host, port);
|
|
14 try {
|
|
15 sessionchannel = SocketChannel.open();
|
|
16 sessionchannel.configureBlocking(true);
|
|
17 sessionchannel.connect(addr);
|
|
18 System.out.println("connect");
|
|
19 //sessionchannel.configureBlocking(false);
|
|
20 while(!sessionchannel.finishConnect()){
|
|
21 System.out.println("afro");
|
|
22 }
|
|
23 //registerChannel(selector, sessionchannel, SelectionKey.OP_READ);
|
|
24 }catch (IOException e) {
|
|
25 e.printStackTrace();
|
|
26 }
|
|
27 }
|
|
28 }
|