package com.pjf;
|
package com.pjf;
|
|
|
import java.io.IOException;
|
import java.io.IOException;
|
import java.net.SocketException;
|
import java.net.SocketException;
|
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
|
|
public class UDPTestStream {
|
public class UDPTestStream {
|
private UDPCxn cxn;
|
private UDPCxn cxn;
|
private Listener listener;
|
private Listener listener;
|
|
|
class Listener extends Thread {
|
class Listener extends Thread {
|
|
|
@Override
|
@Override
|
public void run() {
|
public void run() {
|
byte[] rep;
|
byte[] rep;
|
while (true) {
|
while (true) {
|
try {
|
try {
|
rep = cxn.rcv();
|
rep = cxn.rcv();
|
String reply = new String(rep);
|
String reply = new String(rep);
|
System.out.println("Got [" + reply + "]");
|
System.out.println("Got [" + reply + "]");
|
} catch (IOException e) {
|
} catch (IOException e) {
|
e.printStackTrace();
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
public UDPTestStream() throws SocketException, UnknownHostException {
|
public UDPTestStream() throws SocketException, UnknownHostException {
|
cxn = new UDPCxn("192.168.5.9");
|
cxn = new UDPCxn("192.168.5.9");
|
listener = new Listener();
|
listener = new Listener();
|
listener.start();
|
listener.start();
|
}
|
}
|
|
|
public void go() throws IOException, InterruptedException {
|
public void go() throws IOException, InterruptedException {
|
String fix1 = "1=45~34=";
|
String fix1 = "1=45~34=";
|
String fix2 = "~18=23~";
|
String fix2 = "~18=23~";
|
for (int price=225; price>=150; price--) {
|
for (int price=225; price>=150; price--) {
|
StringBuffer fixmsg = new StringBuffer(fix1);
|
StringBuffer fixmsg = new StringBuffer(fix1);
|
fixmsg.append(Integer.toString(price));
|
fixmsg.append(Integer.toString(price));
|
fixmsg.append(fix2);
|
fixmsg.append(fix2);
|
System.out.println("Sending price tick " + price);
|
System.out.println("Sending price tick " + price);
|
cxn.fixSend(fixmsg.toString(), 2000, false);
|
cxn.fixSend(fixmsg.toString(), 2000, false);
|
}
|
}
|
Thread.sleep(2000);
|
Thread.sleep(2000);
|
}
|
}
|
|
|
|
|
public static void main(String[] args) {
|
public static void main(String[] args) {
|
UDPTestStream ut;
|
UDPTestStream ut;
|
try {
|
try {
|
ut = new UDPTestStream();
|
ut = new UDPTestStream();
|
ut.go();
|
ut.go();
|
} catch (Exception e) {
|
} catch (Exception e) {
|
e.printStackTrace();
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
|
|
|
}
|
}
|
|
|