gpt4 book ai didi

java - 了解 Android 的代码 fragment IP 摄像机

转载 作者:行者123 更新时间:2023-12-02 07:29:19 27 4
gpt4 key购买 nike

任何人请帮助我理解这段代码。这是从 android 的 IPCamera 中获取的,我从 googlecode 中获取的。我试图弄清楚的代码是:

public NanoHTTPD( int port, File wwwroot ) throws IOException
{
myTcpPort = port;
this.myRootDir = wwwroot;
myServerSocket = new ServerSocket( myTcpPort );
myThread = new Thread( new Runnable()
{
public void run()
{
try
{
while( true )
new HTTPSession( myServerSocket.accept());
}
catch ( IOException ioe )
{}
}
});
myThread.setDaemon( true );
myThread.start();
}

private class HTTPSession implements Runnable
{
public HTTPSession( Socket s )
{
mySocket = s;
Thread t = new Thread( this );
t.setDaemon( true );
t.start();
}

public void run()
{
try
{
InputStream is = mySocket.getInputStream();
if ( is == null) return;

我想知道的事情。如果我的理解有误,请告诉我:

1- myServerSocket.accept() 此代码将返回什么? boolean 值是真还是假?

2- InputStream is = mySocket.getInputStream(); 输入流是获取字节流。而是程序在 mySocket 上读取的内容。据我了解,它读取端口号。它与 mySocket 获取字节有什么关系?

如果我的理解完全错误,我真的很抱歉,因为套接字不是我的知识。请帮助我了解更多信息。

最佳答案

这是 ServerSocket 的 accept() method

Waits for an incoming request and blocks until the connection is opened.

Returns

the connection representing socket.

这是getInputStream()其中

Returns an input stream to read data from this socket.

您可能想阅读有关套接字和流的内容。

这是Java的教程All About Sockets .

关于java - 了解 Android 的代码 fragment IP 摄像机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13135475/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com