freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

企業(yè)即時通外文文獻(xiàn)翻譯-在線瀏覽

2024-07-24 16:57本頁面
  

【正文】 tains (among other things) two Streams. One is for reading data ing in, and the other is for writing data is to say, a Socket has an InputStream and an OutputStream.(If these Stream classes are unfamiliar to you, then suffice it to say that they are objects used for reading and writing data, often as a stream of bytes. If you don39。ll call it . The next few panels will show the essential elements of this class: the constructor and the main() routine. The constructor for Server takes a single parameter a port number. This tells us what port to listen on when we are ready to start accepting connections. Here is the constructor: public Server( int port ) throws IOException { // All we have to do is listen listen( port )。ll also include a main() routine so that this Server class can be used as its own standalone application. In practice, you might be embedding your basic server code in something larger, in which case you already have a main(). But for our purposes, the Server is all there is. Here39。 // Create a Server object, which will automatically begin // accepting connections. 4 new Server( port )。re all ready to listen, we39。re ready to start accepting work connections from our clients. Here39。s where the ServerSocket es in. This is an object whose job is simple: listen on a port and when a new connection es in, create a Socket that represents that new connection. Accepting Sockets Remember that your program will potentially be serving many clients from all over the Inter. And these clients will be connecting to your server without regard to each is, there39。ll see later, multithreading is an excellent way to deal with these connections once they have e in. However, we39。s what it looks like, in the abstract: // start listening on the port ServerSocket ss = new ServerSocket( port )。 // deal with the connection // ... } 5 The accept() routine is the key here. When this method of ServerSocket is called, it returns a new Socket object that represents a new connection that has e in. After you39。t any connections ing in at the moment, then the accept () routine simply blocks doesn39。re going to create a new thread to deal with it. Once the new thread is created, it can go off and deal with the new connection, and our whileaccept loop can go back to accepting new connections. If the act of creating this new thread is fast enough, then the connections won39。s take a look at the code that does all this. The code below takes care of the things we39。s take a look: private void listen( int port ) throws IOException { // Create the ServerSocket ss = new ServerSocket( port )。re ready to go ( Listening on +ss )。 // Tell the world we39。 // Create a DataOutputStream for writing data to the // other side DataOutputStream dout = new DataOutputStream( () )。t need to make it again ( s, dout )。 } } The last line of this listing creates a thread to deal with the new connection. This thread is an object called a ServerThread, which is the topic of the next section. 5. PerThread class What is a thread? Two of the Java language39。t support these functions they do. But the abstractions that the Java language uses to provide these features are particularly elegant, especially for a mercial language. A thread is generally defined as a separate line of control within a single process. What this really means is that a multithreaded program has multiple, semiautonomous activities going on inside of it at the same time. Multithreading is similar to the concepts of a task and multitasking, except that the multiple threads within a program all share the same data space. This makes it easier for them to share data directly and efficiently and it also makes it easier for them to mess each other up. Why use multithreading? A detailed discussion of threads is beyond the scope of this tutorial. There are a few reasons why you39。s waiting for user 0 to say something, then it39。re going to create a thread for each user connected to the system. The advantage of multithreading is that when one thread is listening for a slow user to say something, it essentially goes to sleep 7 until something es in from that user. In the meantime, another thread can be receiving data from another user. In effect, multithreading allows us to respond as quickly as we can to each user. In Java programs, any class can be made into a thread by implementing the Runnable interface. Or you can simply subclass from the class . We have chosen the latter route, for no particular reason: public class ServerThread extends Thread { // ... } The Socket object is essential, because the whole purpose of this thread is to use a socket to municate with the other side. Here39。 = socket。 } 6. The Client class Now that we39。re going to be talking to the client, we should talk a little bit about our munic
點擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1