Last active
December 17, 2015 21:09
-
-
Save rodrigoSaladoAnaya/5672622 to your computer and use it in GitHub Desktop.
Ejemplo de como se manda una trama tipo 'eco' a test (Vertx)
This file contains 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
import static org.vertx.groovy.core.streams.Pump.createPump | |
import org.vertx.groovy.core.buffer.Buffer | |
def client = vertx.createNetClient() | |
client.connect(1234, "201.000.000.000") { socket -> | |
println "Conectado!" | |
def key = "08000220000100000000051300240412655910MEXWS1TEST" | |
byte[] bytesKey = new byte[key.bytes.length + 3] | |
for(int i = 2; i < key.bytes.length + 2; i++){ | |
bytesKey[i] = key.bytes[i - 2] | |
} | |
byte c = 0 | |
byte l = bytesKey.length - 2 | |
byte ext = 3 | |
bytesKey[0] = c | |
bytesKey[1] = l | |
bytesKey[key.bytes.length + 2] = ext | |
def myBuffer2 = new Buffer(bytesKey) | |
socket.write(myBuffer2){ println "Enviando Tx..." } | |
socket.dataHandler { buffer -> | |
println "Respuesta: {${new String(buffer.bytes[2..buffer.length - 2] as byte[], 'UTF-8')}}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment