5
|
1 package rep.net;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetSocketAddress;
|
|
5 import java.nio.channels.SocketChannel;
|
|
6
|
|
7 import rep.REPCommand;
|
|
8 import rep.REPPacketReceive;
|
|
9 import rep.REPPacketSend;
|
133
|
10 import rep.channel.REPSocketChannel;
|
5
|
11
|
|
12 public class REPNet {
|
133
|
13 private REPSocketChannel<REPCommand> sc;
|
|
14 public REPPacketReceive repreceive;
|
5
|
15 private REPPacketSend repsend;
|
|
16
|
|
17 public void sm_connect(String host, int port){
|
|
18 //int port = 8765;
|
|
19 //String host = "localhost";
|
|
20 InetSocketAddress addr = new InetSocketAddress(host, port);
|
|
21 try {
|
133
|
22 sc = REPSocketChannel.open();
|
5
|
23 sc.configureBlocking(true);
|
|
24 sc.connect(addr);
|
|
25 while(!sc.finishConnect()){
|
|
26 System.out.println("afro");
|
|
27 }
|
|
28 }catch (IOException e) {
|
|
29 e.printStackTrace();
|
|
30 }
|
|
31 repreceive = new REPPacketReceive(sc);
|
|
32 repsend = new REPPacketSend(sc);
|
|
33 }
|
|
34
|
|
35 public void send(REPCommand command) {
|
|
36 repsend.send(command);
|
|
37 }
|
|
38 }
|