package file;
import java.net.*;
//import java.util.StringTokenizer;
class TestList {
public static void main(String argv[]) {
A a = new A();
a.start();
}
}
class A extends Thread {
final static int port = 8532;
final static int taille = 1024;
final static byte buffer[] = new byte[taille];
public void run() {
try {
InetAddress serveur = InetAddress.getByName("147.127.240.91");
//------------ send request ------------------
String s = "Song Request";
int length = s.length();
byte buffer[] = s.getBytes();
DatagramPacket dataSent = new DatagramPacket(buffer, length, serveur, 8532);
DatagramSocket socket = new DatagramSocket();
socket.send(dataSent);
//---------- received response ---------------
DatagramPacket dataReceived = new DatagramPacket(new byte[taille], taille);
socket.receive(dataReceived);
String songListRecieved = new String(dataReceived.getData(), 0, dataReceived.getLength());
String songName[] = songListRecieved.split("\\|");
for ( String tmpStr : songName )
System.out.println("Data received : " + tmpStr.trim() );
// --------- choose song ---------------------
length = songName[1].length();
buffer = songName[1].getBytes();
dataSent = new DatagramPacket(buffer, length, serveur, 8532);
socket.send(dataSent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
วันอังคารที่ 1 ธันวาคม พ.ศ. 2552
UDP Socket Client
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น