當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Processing Server.disconnect()用法及代碼示例


Processing, 類Server中的disconnect()用法介紹。

用法

  • server.disconnect(client)

參數

  • server (Server) 服務器類型的任何變量
  • client (Client) 客戶端斷開連接

返回

  • void

說明

斷開特定客戶端。

例子

import processing.net.*;

int port = 10002;
Server myServer;

void setup()
{
  size(400, 400);
  background(0);
  myServer = new Server(this, port);
}

void draw()
{
  // Get the next available client
  Client thisClient = myServer.available();
  // If the client is not null, and says something, display what it said:
  if (thisClient !=null) {
    String whatClientSaid = thisClient.readString();
    // If the client says "exit", disconnect it
    if (whatClientSaid.equals("exit\r\n")) {
      thisClient.write("You will be disconnected now.\r\n");
      println(thisClient.ip() + "\t has been disconnected");
      myServer.disconnect(thisClient);
    } 
  } 
}

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 Server.disconnect()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。