【正文】
300)。 setLayout(newpublic class Face extends Frame {主要是JAVA按鈕,文本域,標簽,布局管理器的使用。 public void dataout(String data) { } (())。 } (readin + \n)。 readin = ()。// 新建Socket對象 try { } catch (IOException e) { = chat。 // 端口號import .*。建好連接后,用戶通過得到Socket的輸入輸出流對象后,利用流的方法實現(xiàn)數(shù)據(jù)的傳輸。 } } catch (IOException err) { ()。()。 i 。 } catch (SocketException e) {try { } return 。 } = chat。 Client = s。 = ++i。 } } //theOutputStream = new PrintStream(null)。 //for(int j=0。 l=。 if (i 2) { Client[k] = ()。 } public Server(int port, Face chat) {Face chat。PrintStream theOutputStream。 int port,k=0,l=0。 TextArea in。 int i = 0。 Socket Client1=null。 Socket Client[ ]=new Socket[10]。public class Server extends Thread {ServerSocket skt。具體代碼如下:package 。四、詳細設計客戶端不需要指定打開的端口,通常臨時的、動態(tài)的分配一個端口。實現(xiàn)了好友添加,消息收發(fā)、顯示等基本功能。二、設計思路分析1. 在網絡越來越發(fā)達的今天,人們對網絡的依賴越來越強,網絡聊天已經成了許多人生活中必不可少的一部分,基于這樣的需求,出現(xiàn)了許多網絡聊天通信工具,像,MSN等等,但是人們已經不再滿足于單一的兩個人之間的聊天,而是對多人同時聊天產生了興趣,于是出現(xiàn)了網絡聊天室,不同地方的人可以在那個虛擬的聊天室里面熱烈聊天。 s end between two procedures that are operated on the network based on TCP/IP. bag includes Sockets, which is used to develop the network munication procedure paper probes into the general structurebased on Socket munication procedure of Java through the instance general munication software can be developed basedon this one,so there is certain reference value.Key words : ava。對開發(fā)一般性的通信軟件, 有一定的參考價值。通過實例模型探討基于Java 的Socket 通信程序的一般結構。 SocketSocket Programming Based on TCP/IP in JavaAbstract :Socket is one of the two way munication39。munication一、課題內容和要求基于Socket和多線程編程的聊天程序實現(xiàn)網絡聊天程序設計非常復雜,允許多個人同時聊天更加需要多線程技術的支持,請實現(xiàn)一個簡單的多線程網絡聊天程序模擬。,我們采用圖形化的用戶界面。當一個Socket會話產生后,將這個會話交給線程處理,然后主程序繼續(xù)監(jiān)聽。(Client)客戶端,使用Socket對網絡上某一個服務器的某一個端口發(fā)出連接請求,一旦連接成功,打開會話;會話完成后,關閉Socket。下面