廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 3089 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
skygp
個人文章 個人相簿 個人日記 個人地圖
初露鋒芒
級別: 初露鋒芒 該用戶目前不上站
推文 x0 鮮花 x104
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[Java] 一個關於server的java程式
希望看的懂的人
能給我一些註解
非常感謝


import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Server extends JFrame {
private JTextField enterField;
private JTextArea displayArea;
private ObjectOutputStream output;
private ObjectInputStream input;
private ServerSocket server;
private Socket connection;
private int counter = 1;

// set up GUI
public Server()
{
super( "Server" );

Container container = getContentPane();

// create enterField and register listener
enterField = new JTextField();
enterField.setEditable( false );
enterField.addActionListener(
new ActionListener() {

// send message to client
public void actionPerformed( ActionEvent event )
{
sendData( event.getActionCommand() );
enterField.setText( "" );
}
}
);

container.add( enterField, BorderLayout.NORTH );

// create displayArea
displayArea = new JTextArea();
container.add( new JScrollPane( displayArea ),
BorderLayout.CENTER );

setSize( 300, 150 );
setVisible( true );

} // end Server constructor

// set up and run server
public void runServer()
{
// set up server to receive connections; process connections
try {

// Step 1: Create a ServerSocket.
server = new ServerSocket( 12345, 100 );

while ( true ) {

try {
waitForConnection(); // Step 2: Wait for a connection.
getStreams(); // Step 3: Get input & output streams.
processConnection(); // Step 4: Process connection.
}

// process EOFException when client closes connection
catch ( EOFException eofException ) {
System.err.println( "Server terminated connection" );
}

finally {
closeConnection(); // Step 5: Close connection.
++counter;
}

} // end while

} // end try

// proc ..

訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容




獻花 x0 回到頂端 [樓 主] From:台灣中華電信 | Posted:2006-05-21 12:25 |
neyney1
個人頭像
個人文章 個人相簿 個人日記 個人地圖
小有名氣
級別: 小有名氣 該用戶目前不上站
推文 x0 鮮花 x49
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

這支程式應該還有搭配一個client的程式吧,
不然run起來就只有server的畫面,
你也不知道會有什麼反應,
但是這支的功能應該就是把client對server連線後
把client輸出的東西顯示在server上面
應該就是這樣吧


獻花 x0 回到頂端 [1 樓] From:台灣中華電信 | Posted:2006-05-24 15:49 |
skygp
個人文章 個人相簿 個人日記 個人地圖
初露鋒芒
級別: 初露鋒芒 該用戶目前不上站
推文 x0 鮮花 x104
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

他的確搭配一個client的程式吧
但我想說先看懂這一個


獻花 x0 回到頂端 [2 樓] From:台灣教育部 | Posted:2006-05-25 10:04 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.015100 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言