我用C编写了一个网络ICMP ping代码,以下是我的代码,它试图ping上千个IP,但是运行几天后,打开套接字的总数增加到35K。我应该在哪里释放插座。
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.events.AbstractWebDriverEventListener;
import org.openqa.selenium.support.events.EventFiringWebDriver;
public class HighLighterEventListener extends AbstractWebDriverEventListener {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "./libs/chromedriver 4");
WebDriver webdriver=new ChromeDriver();
EventFiringWebDriver driver = new EventFiringWebDriver(webdriver);
webdriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://yosuva.com");
driver.register(new HighLighterEventListener());
driver.findElement(By.xpath("//span[text()='Home']"));
driver.findElement(By.xpath("//span[text()='About']"));
driver.findElement(By.xpath("//span[text()='Tools']"));
driver.findElement(By.xpath("//span[text()='News']"));
driver.findElement(By.xpath("//span[text()='Events']"));
driver.findElement(By.xpath("//span[text()='Contact']"));
driver.quit();
}
@Override
public void afterFindBy(By by, WebElement element, WebDriver driver) {
((JavascriptExecutor)driver).executeScript(
"arguments[0].style.border='3px solid green'",element
);
}
}
答案 0 :(得分:1)
您应该在函数结束时关闭套接字。在for循环之后。