서버
뷰어
데이터변경
more..
package Ex;
import java.net.*;
import java.io.*;
public class Ex03_07 {
public static void main(String[] args) {
DatagramSocket ds = null;
DatagramPacket dp = null;
try {
ds = new DatagramSocket(54329);
} catch (SocketException ee) {
ee.printStackTrace();
}
byte[] aa = new byte[65508];
while (true) {
dp = new DatagramPacket(aa, aa.length);
try {
ds.receive(dp);
} catch (IOException ee) {
ee.printStackTrace();
}
byte[] bbb = new String(dp.getData()).trim().getBytes();
for (int i = 54322; i < 54324; i++) {
try {
dp = new DatagramPacket(bbb, bbb.length, InetAddress
.getByName("220.81.20.109"), i);
} catch (UnknownHostException ee) {
ee.printStackTrace();
}
try {
ds.send(dp);
} catch (IOException ee) {
ee.printStackTrace();
}
}
}
}
}
import java.net.*;
import java.io.*;
public class Ex03_07 {
public static void main(String[] args) {
DatagramSocket ds = null;
DatagramPacket dp = null;
try {
ds = new DatagramSocket(54329);
} catch (SocketException ee) {
ee.printStackTrace();
}
byte[] aa = new byte[65508];
while (true) {
dp = new DatagramPacket(aa, aa.length);
try {
ds.receive(dp);
} catch (IOException ee) {
ee.printStackTrace();
}
byte[] bbb = new String(dp.getData()).trim().getBytes();
for (int i = 54322; i < 54324; i++) {
try {
dp = new DatagramPacket(bbb, bbb.length, InetAddress
.getByName("220.81.20.109"), i);
} catch (UnknownHostException ee) {
ee.printStackTrace();
}
try {
ds.send(dp);
} catch (IOException ee) {
ee.printStackTrace();
}
}
}
}
}
뷰어
more..
package Ex;
import java.io.*;
import java.net.*;
import java.awt.*;
class Ex03_08sub extends Frame implements Runnable {
private Label lb = new Label("변동 내용 : ", Label.RIGHT);
private Label lb1 = new Label("0", Label.CENTER);
private Thread currentTh;
private int iii;
public Ex03_08sub(String str, int i) {
super(str);
this.iii = i;
this.init();
this.start();
this.setSize(300, 200);
this.setVisible(true);
}
public void init() {
this.setLayout(new BorderLayout());
this.add("West", lb);
this.add("Center", lb1);
currentTh = new Thread(this);
currentTh.start();
}
public void start() {
}
public void run() {
DatagramSocket ds = null;
try {
ds = new DatagramSocket(iii);
} catch (SocketException ee) {
ee.printStackTrace();
}
DatagramPacket dp = null;
while (true) {
try {
dp = new DatagramPacket(new byte[65508], 65508);
ds.receive(dp);
lb1.setText(new String(dp.getData()).trim());
} catch (IOException ee) {
ee.printStackTrace();
}
}
}
}
public class Ex03_08 {
public static void main(String[] args) {
for (int ii = 54322; ii < 54324; ii++) {
Ex03_08sub es = new Ex03_08sub("뷰어", ii);
}
}
}
import java.io.*;
import java.net.*;
import java.awt.*;
class Ex03_08sub extends Frame implements Runnable {
private Label lb = new Label("변동 내용 : ", Label.RIGHT);
private Label lb1 = new Label("0", Label.CENTER);
private Thread currentTh;
private int iii;
public Ex03_08sub(String str, int i) {
super(str);
this.iii = i;
this.init();
this.start();
this.setSize(300, 200);
this.setVisible(true);
}
public void init() {
this.setLayout(new BorderLayout());
this.add("West", lb);
this.add("Center", lb1);
currentTh = new Thread(this);
currentTh.start();
}
public void start() {
}
public void run() {
DatagramSocket ds = null;
try {
ds = new DatagramSocket(iii);
} catch (SocketException ee) {
ee.printStackTrace();
}
DatagramPacket dp = null;
while (true) {
try {
dp = new DatagramPacket(new byte[65508], 65508);
ds.receive(dp);
lb1.setText(new String(dp.getData()).trim());
} catch (IOException ee) {
ee.printStackTrace();
}
}
}
}
public class Ex03_08 {
public static void main(String[] args) {
for (int ii = 54322; ii < 54324; ii++) {
Ex03_08sub es = new Ex03_08sub("뷰어", ii);
}
}
}
데이터변경
more..
package Ex;
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class Ex03_06sub extends Frame implements ActionListener {
private Label lb = new Label("변동 데이터 = ", Label.RIGHT);
private TextField tf = new TextField(20);
public Ex03_06sub(String str) {
super(str);
this.init();
this.start();
this.setSize(300, 200);
this.setVisible(true);
}
public void init() {
this.setLayout(new FlowLayout());
this.add(lb);
this.add(tf);
}
public void start() {
tf.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == tf) {
String str = tf.getText().trim();
if (str.equals("") || str.length() == 0) {
tf.setText("");
tf.requestFocus();
return;
}
byte[] data = str.getBytes();
DatagramPacket dp = null;
try{
dp = new DatagramPacket(data, data.length,
InetAddress.getByName("220.81.20.109"),54329);
}catch(UnknownHostException ee){ee.printStackTrace();}
DatagramSocket ds = null;
try{
ds = new DatagramSocket();
ds.send(dp);
ds.close();
}catch(IOException ee){ee.printStackTrace();}
}
}
}
public class Ex03_06 {
public static void main(String ar[]) {
Ex03_06sub ex = new Ex03_06sub("실시간 변동 데이터");
}
}
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class Ex03_06sub extends Frame implements ActionListener {
private Label lb = new Label("변동 데이터 = ", Label.RIGHT);
private TextField tf = new TextField(20);
public Ex03_06sub(String str) {
super(str);
this.init();
this.start();
this.setSize(300, 200);
this.setVisible(true);
}
public void init() {
this.setLayout(new FlowLayout());
this.add(lb);
this.add(tf);
}
public void start() {
tf.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == tf) {
String str = tf.getText().trim();
if (str.equals("") || str.length() == 0) {
tf.setText("");
tf.requestFocus();
return;
}
byte[] data = str.getBytes();
DatagramPacket dp = null;
try{
dp = new DatagramPacket(data, data.length,
InetAddress.getByName("220.81.20.109"),54329);
}catch(UnknownHostException ee){ee.printStackTrace();}
DatagramSocket ds = null;
try{
ds = new DatagramSocket();
ds.send(dp);
ds.close();
}catch(IOException ee){ee.printStackTrace();}
}
}
}
public class Ex03_06 {
public static void main(String ar[]) {
Ex03_06sub ex = new Ex03_06sub("실시간 변동 데이터");
}
}
http://dynast.tistory.com/trackback/140


이올린에 북마크하기
이올린에 추천하기



