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


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

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

用法

  • server.stop()

參數

  • server (Server) 服務器類型的任何變量

返回

  • void

說明

斷開所有客戶端並停止服務器。

例子

// Bug note: stopping the server produces an unrecoverable error:
// "java.net.SocketException: Socket closed
//  at java.net.PlainSocketImpl.socketAccept(Native Method)"
 
import processing.net.*;

int port = 10002;
boolean myServerRunning;
Server myServer;

void setup()
{
  size(400, 400);
  background(0);
  myServerRunning = false;
  println("Server Running:" + "\t" + myServerRunning);
}

void draw() {
  // Nothing happening here, everything happens in mousePressed()
}

void mousePressed()
{
  // If the mouse clicked the myServer changes status
  println("click");
  if (myServerRunning) {
    // N.B. This produces an error which kills the applet.
    myServerRunning = false;
    myServer.stop();
    myServer = null;
  } 
  else {
    myServer = new Server(this, port); // Starts a server on port 10002
    myServerRunning = true;

  }
  background(0);
  println("Server Status:" + "\t" + myServerRunning);
}

相關用法


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