yangfanconan 发表于 2013-7-8 17:52:59

Processing之旅-----【给鱼插上翅膀,Processing基础扩展库3】

下面我们继续学习Processing中自带的库-----Net

这个库主要是网络通信的,虽然没有看过源码,我估计net库实际上就是Processing的一个socket封装库。

/**
* HTTP Client.
*
* Starts a network client that connects to a server on port 80,
* sends an HTTP 1.0 GET request, and prints the results.
*
* Note that this code is not necessary for simple HTTP GET request:
* Simply calling loadStrings("http://www.processing.org") would do
* the same thing as (and more efficiently than) this example.
* This example is for people who might want to do something more
* complicated later.
*/


import processing.net.*;

Client c;
String data;

void setup() {
size(200, 200);
background(50);
fill(200);
c = new Client(this, "www.processing.org", 80); // 链接服务器端口80 此处属于网络知识不另行进行说明
c.write("GET / HTTP/1.0\r\n"); // 用HTTP的get方式进行申请获取网页数据
c.write("\r\n");
}

void draw() {
if (c.available() > 0) { //如果有数据
    data = c.readString(); // 输出
    println(data);
}
}


就socket编程而言可以做很多东西,比如聊天软件啊,局域网游戏啊。等等。
在本课程中就不对socket部分进行详细说明,有兴趣的同学可以谷歌,百度自行了解。

laozjx 发表于 2016-6-22 17:01:32

谢谢楼主,学习。
页: [1]
查看完整版本: Processing之旅-----【给鱼插上翅膀,Processing基础扩展库3】