极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17022|回复: 1

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

[复制链接]
发表于 2013-7-8 17:52:59 | 显示全部楼层 |阅读模式
下面我们继续学习Processing中自带的库-----Net

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

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


  13. import processing.net.*;

  14. Client c;
  15. String data;

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

  24. void draw() {
  25.   if (c.available() > 0) { //如果有数据
  26.     data = c.readString(); // 输出
  27.     println(data);
  28.   }
  29. }
复制代码


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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2016-6-22 17:01:32 | 显示全部楼层
谢谢楼主,学习。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-19 18:58 , Processed in 0.041353 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表