Created
February 3, 2012 15:10
-
-
Save keesun/1730614 to your computer and use it in GitHub Desktop.
Vert.x NetClient Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package echo; | |
| import org.vertx.java.core.Handler; | |
| import org.vertx.java.core.app.VertxApp; | |
| import org.vertx.java.core.buffer.Buffer; | |
| import org.vertx.java.core.net.NetClient; | |
| import org.vertx.java.core.net.NetSocket; | |
| /** | |
| * @author Keesun Baik | |
| */ | |
| public class EchoClient implements VertxApp { | |
| @Override | |
| public void start() throws Exception { | |
| new NetClient().connect(8080, "localhost", new Handler<NetSocket>() { | |
| @Override | |
| public void handle(NetSocket socket) { | |
| System.out.println("Connected!!"); | |
| // 서버에서 메시지가 오면... | |
| socket.dataHandler(new Handler<Buffer>() { | |
| @Override | |
| public void handle(Buffer buffer) { | |
| System.out.println("서버에서 온 메시지: " + buffer); | |
| } | |
| }); | |
| socket.write("hi"); | |
| } | |
| }); | |
| } | |
| @Override | |
| public void stop() throws Exception { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment