Processing UDP 服務端 客戶端 程序代碼

服務端代碼:

import hypermedia.net.*;
UDP udp; 
void setup() {
  udp = new UDP( this, 6000 );
  udp.listen( true );
}
void draw() {;}
void receive( byte[] data, String ip, int port ) {
  data = subset(data, 0, data.length-2);
  String message = new String( data );
  println( "receive: \""+message+"\" from "+ip+" on port "+port );
}

客戶端代碼:

import hypermedia.net.*;
UDP udp;
void setup() {
  udp = new UDP( this, 6100 );
}
void draw() {;}
void keyPressed() {
    String message  = str( key );	// the message to send
    String ip       = "localhost";	// the remote IP address
    int port        = 6000;		// the destination port
    message = message+";\n";
    udp.send( message, ip, port );
}






發佈了88 篇原創文章 · 獲贊 46 · 訪問量 54萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章