真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java安卓聊天室源代碼 java聊天室實(shí)現(xiàn)原理

java實(shí)現(xiàn)聊天室是怎么做到的?

Java 實(shí)現(xiàn)聊天室可以分為以下幾個(gè)步驟:

十載的鐵西網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整鐵西建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“鐵西網(wǎng)站設(shè)計(jì)”,“鐵西網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

建立服務(wù)器端

首先需要建立一個(gè)服務(wù)器端,負(fù)責(zé)接收客戶端的連接請(qǐng)求并處理客戶端發(fā)送過來的消息。

建立客戶端

然后需要建立客戶端,客戶端通過網(wǎng)絡(luò)連接到服務(wù)器端,并向服務(wù)器端發(fā)送消息。

實(shí)現(xiàn)通信協(xié)議

為了實(shí)現(xiàn)聊天室功能,需要定義一個(gè)通信協(xié)議,規(guī)定客戶端和服務(wù)器端之間的通信格式,例如消息的頭部和內(nèi)容等。

實(shí)現(xiàn)多線程處理

聊天室通常會(huì)有多個(gè)用戶同時(shí)在線,因此需要使用多線程來處理多個(gè)客戶端的連接請(qǐng)求和消息傳遞。

實(shí)現(xiàn)GUI界面(可選)

為了方便用戶使用,可以實(shí)現(xiàn)一個(gè)GUI界面,讓用戶可以方便地發(fā)送和接收消息。

以下是一個(gè)簡(jiǎn)單的 Java 聊天室的代碼示例:

java

Copy code

// 服務(wù)器端代碼

public class Server {

public static void main(String[] args) {

try {

ServerSocket serverSocket = new ServerSocket(8888);

while (true) {

Socket socket = serverSocket.accept();

new Thread(new ServerThread(socket)).start();

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

class ServerThread implements Runnable {

private Socket socket;

private BufferedReader reader;

private PrintWriter writer;

public ServerThread(Socket socket) {

this.socket = socket;

try {

reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

writer = new PrintWriter(socket.getOutputStream());

} catch (IOException e) {

e.printStackTrace();

}

}

public void run() {

try {

String msg;

while ((msg = reader.readLine()) != null) {

// 處理客戶端發(fā)送過來的消息

System.out.println("接收到消息:" + msg);

// 將消息發(fā)送給所有客戶端

for (Socket s : ServerThreadList.getList()) {

if (s != socket) {

PrintWriter w = new PrintWriter(s.getOutputStream());

w.println(msg);

w.flush();

}

}

}

// 關(guān)閉連接

socket.close();

ServerThreadList.removeThread(this);

} catch (IOException e) {

e.printStackTrace();

}

}

}

class ServerThreadList {

private static List

list = new ArrayList();

public static void addThread(ServerThread thread) {

list.add(thread);

}

public static void removeThread(ServerThread thread) {

list.remove(thread);

}

public static List

getList() {

return list;

}

}

// 客戶端代碼

public class Client {

public static void main(String[] args) {

try {

Socket socket = new Socket("localhost", 8888);

new Thread(new ClientThread(socket)).start();

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

PrintWriter writer = new PrintWriter(socket.getOutputStream());

while (true) {

String msg = reader.readLine();

writer.println(msg);

writer.flush();

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

class ClientThread implements Runnable {

private Socket socket;

private BufferedReader reader;

public ClientThread(Socket socket) {

this.socket = socket;

try {

reader

求java網(wǎng)絡(luò)聊天室(B/S模式)程序代碼

共四個(gè)java文件,源代碼如下:

import java.awt.*;

import java點(diǎn)虐 .*;

import java.awt.event.*;

import java.io.*;

import java.util.Hashtable;

public class ChatArea extends Panel implements ActionListener,Runnable

{

Socket socket=null;

DataInputStream in=null;

DataOutputStream out=null;

Thread threadMessage=null;

TextArea 談話顯示區(qū),私聊顯示區(qū)=null;

TextField 送出信息=null;

Button 確定,刷新談話區(qū),刷新私聊區(qū);

Label 提示條=null;

String name=null;

Hashtable listTable;

List listComponent=null;

Choice privateChatList;

int width,height;

public ChatArea(String name,Hashtable listTable,int width,int height)

{

setLayout(null);

setBackground(Color.orange);

this.width=width;

this.height=height;

setSize(width,height);

this.listTable=listTable;

this.name=name;

threadMessage=new Thread(this);

談話顯示區(qū)=new TextArea(10,10);

私聊顯示區(qū)=new TextArea(10,10);

確定=new Button("送出信息到:");

刷新談話區(qū)=new Button("刷新談話區(qū)");

刷新私聊區(qū)=new Button("刷新私聊區(qū)");

提示條=new Label("雙擊聊天者可私聊",Label.CENTER);

送出信息=new TextField(28);

確定.addActionListener(this);

送出信息.addActionListener(this);

刷新談話區(qū).addActionListener(this);

刷新私聊區(qū).addActionListener(this);

listComponent=new List();

listComponent.addActionListener(this);

privateChatList=new Choice();

privateChatList.add("大家(*)");

privateChatList.select(0);

add(談話顯示區(qū));

談話顯示區(qū).setBounds(10,10,(width-120)/2,(height-120));

add(私聊顯示區(qū));

私聊顯示區(qū).setBounds(10+(width-120)/2,10,(width-120)/2,(height-120));

add(listComponent);

listComponent.setBounds(10+(width-120),10,100,(height-160));

add(提示條);

提示條.setBounds(10+(width-120),10+(height-160),110,40);

Panel pSouth=new Panel();

pSouth.add(送出信息);

pSouth.add(確定);

pSouth.add(privateChatList);

pSouth.add(刷新談話區(qū));

pSouth.add(刷新私聊區(qū));

add(pSouth);

pSouth.setBounds(10,20+(height-120),width-20,60);

}

public void setName(String s)

{

name=s;

}

public void setSocketConnection(Socket socket,DataInputStream in,DataOutputStream out)

{

this.socket=socket;

this.in=in;

this.out=out;

try

{

threadMessage.start();

}

catch(Exception e)

{

}

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==確定||e.getSource()==送出信息)

{

String message="";

String people=privateChatList.getSelectedItem();

people=people.substring(0,people.indexOf("("));

message=送出信息.getText();

if(message.length()0)

{

try {

if(people.equals("大家"))

{

out.writeUTF("公共聊天內(nèi)容:"+name+"說:"+message);

}

else

{

out.writeUTF("私人聊天內(nèi)容:"+name+"悄悄地說:"+message+"#"+people);

}

}

catch(IOException event)

{

}

}

}

else if(e.getSource()==listComponent)

{

privateChatList.insert(listComponent.getSelectedItem(),0);

privateChatList.repaint();

}

else if(e.getSource()==刷新談話區(qū))

{

談話顯示區(qū).setText(null);

}

else if(e.getSource()==刷新私聊區(qū))

{

私聊顯示區(qū).setText(null);

}

}

public void run()

{

while(true)

{

String s=null;

try

{

s=in.readUTF();

if(s.startsWith("聊天內(nèi)容:"))

{

String content=s.substring(s.indexOf(":")+1);

談話顯示區(qū).append("\n"+content);

}

if(s.startsWith("私人聊天內(nèi)容:"))

{

String content=s.substring(s.indexOf(":")+1);

私聊顯示區(qū).append("\n"+content);

}

else if(s.startsWith("聊天者:"))

{

String people=s.substring(s.indexOf(":")+1,s.indexOf("性別"));

String sex=s.substring(s.indexOf("性別")+2);

listTable.put(people,people+"("+sex+")");

listComponent.add((String)listTable.get(people));

listComponent.repaint();

}

else if(s.startsWith("用戶離線:"))

{

String awayPeopleName=s.substring(s.indexOf(":")+1);

listComponent.remove((String)listTable.get(awayPeopleName));

listComponent.repaint();

談話顯示區(qū).append("\n"+(String)listTable.get(awayPeopleName)+"離線");

listTable.remove(awayPeopleName);

}

Thread.sleep(5);

}

catch(IOException e)

{

listComponent.removeAll();

listComponent.repaint();

listTable.clear();

談話顯示區(qū).setText("和服務(wù)器的連接已中斷\n必須刷新瀏覽器才能再次聊天");

break;

}

catch(InterruptedException e)

{

}

}

}

}

ChatServer.java

import java.io.*;

import java點(diǎn)虐 .*;

import java.util.*;

public class ChatServer

{

public static void main(String args[])

{

ServerSocket server=null;

Socket you=null;

Hashtable peopleList;

peopleList=new Hashtable();

while(true)

{

try

{

server=new ServerSocket(6666);

}

catch(IOException e1)

{

System.out.println("正在監(jiān)聽");

}

try {

you=server.accept();

InetAddress address=you.getInetAddress();

System.out.println("用戶的IP:"+address);

}

catch (IOException e)

{

}

if(you!=null)

{

Server_thread peopleThread=new Server_thread(you,peopleList);

peopleThread.start();

}

else {

continue;

}

}

}

}

class Server_thread extends Thread

{

String name=null,sex=null;

Socket socket=null;

File file=null;

DataOutputStream out=null;

DataInputStream in=null;

Hashtable peopleList=null;

Server_thread(Socket t,Hashtable list)

{

peopleList=list;

socket=t;

try {

in=new DataInputStream(socket.getInputStream());

out=new DataOutputStream(socket.getOutputStream());

}

catch (IOException e)

{

}

}

public void run()

{

while(true)

{ String s=null;

try

{

s=in.readUTF();

if(s.startsWith("姓名:"))

{

name=s.substring(s.indexOf(":")+1,s.indexOf("性別"));

sex=s.substring(s.lastIndexOf(":")+1);

boolean boo=peopleList.containsKey(name);

if(boo==false)

{

peopleList.put(name,this);

out.writeUTF("可以聊天:");

Enumeration enum=peopleList.elements();

while(enum.hasMoreElements())

{

Server_thread th=(Server_thread)enum.nextElement();

th.out.writeUTF("聊天者:"+name+"性別"+sex);

if(th!=this)

{

out.writeUTF("聊天者:"+th.name+"性別"+th.sex);

}

}

}

else

{

out.writeUTF("不可以聊天:");

}

}

else if(s.startsWith("公共聊天內(nèi)容:"))

{

String message=s.substring(s.indexOf(":")+1);

Enumeration enum=peopleList.elements();

while(enum.hasMoreElements())

{

((Server_thread)enum.nextElement()).out.writeUTF("聊天內(nèi)容:"+message);

}

}

else if(s.startsWith("用戶離開:"))

{

Enumeration enum=peopleList.elements();

while(enum.hasMoreElements())

{ try

{

Server_thread th=(Server_thread)enum.nextElement();

if(th!=thisth.isAlive())

{

th.out.writeUTF("用戶離線:"+name);

}

}

catch(IOException eee)

{

}

}

peopleList.remove(name);

socket.close();

System.out.println(name+"用戶離開了");

break;

}

else if(s.startsWith("私人聊天內(nèi)容:"))

{

String 悄悄話=s.substring(s.indexOf(":")+1,s.indexOf("#"));

String toPeople=s.substring(s.indexOf("#")+1);

Server_thread toThread=(Server_thread)peopleList.get(toPeople);

if(toThread!=null)

{

toThread.out.writeUTF("私人聊天內(nèi)容:"+悄悄話);

}

else

{

out.writeUTF("私人聊天內(nèi)容:"+toPeople+"已經(jīng)離線");

}

}

}

catch(IOException ee)

{

Enumeration enum=peopleList.elements();

while(enum.hasMoreElements())

{ try

{

Server_thread th=(Server_thread)enum.nextElement();

if(th!=thisth.isAlive())

{

th.out.writeUTF("用戶離線:"+name);

}

}

catch(IOException eee)

{

}

}

peopleList.remove(name);

try

{

socket.close();

}

catch(IOException eee)

{

}

System.out.println(name+"用戶離開了");

break;

}

}

}

}

import java.awt.*;

import java.io.*;

import java點(diǎn)虐 .*;

import java.applet.*;

import java.util.Hashtable;

ClientChat.java

public class ClientChat extends Applet implements Runnable

{

Socket socket=null;

DataInputStream in=null;

DataOutputStream out=null;

InputNameTextField 用戶提交昵稱界面=null;

ChatArea 用戶聊天界面=null;

Hashtable listTable;

Label 提示條;

Panel north, center;

Thread thread;

public void init()

{

int width=getSize().width;

int height=getSize().height;

listTable=new Hashtable();

setLayout(new BorderLayout());

用戶提交昵稱界面=new InputNameTextField(listTable);

int h=用戶提交昵稱界面.getSize().height;

用戶聊天界面=new ChatArea("",listTable,width,height-(h+5));

用戶聊天界面.setVisible(false);

提示條=new Label("正在連接到服務(wù)器,請(qǐng)稍等...",Label.CENTER);

提示條.setForeground(Color.red);

north=new Panel(new FlowLayout(FlowLayout.LEFT));

center=new Panel();

north.add(用戶提交昵稱界面);

north.add(提示條);

center.add(用戶聊天界面);

add(north,BorderLayout.NORTH);

add(center,BorderLayout.CENTER);

validate();

}

public void start()

{

if(socket!=nullin!=nullout!=null)

{ try

{

socket.close();

in.close();

out.close();

用戶聊天界面.setVisible(false);

}

catch(Exception ee)

{

}

}

try

{

socket = new Socket(this.getCodeBase().getHost(), 6666);

in=new DataInputStream(socket.getInputStream());

out=new DataOutputStream(socket.getOutputStream());

}

catch (IOException ee)

{

提示條.setText("連接失敗");

}

if(socket!=null)

{

InetAddress address=socket.getInetAddress();

提示條.setText("連接:"+address+"成功");

用戶提交昵稱界面.setSocketConnection(socket,in,out);

north.validate();

}

if(thread==null)

{

thread=new Thread(this);

thread.start();

}

}

public void stop()

{

try

{

socket.close();

thread=null;

}

catch(IOException e)

{

this.showStatus(e.toString());

}

}

public void run()

{

while(thread!=null)

{

if(用戶提交昵稱界面.get能否聊天()==true)

{

用戶聊天界面.setVisible(true);

用戶聊天界面.setName(用戶提交昵稱界面.getName());

用戶聊天界面.setSocketConnection(socket,in,out);

提示條.setText("祝聊天愉快!");

center.validate();

break;

}

try

{

Thread.sleep(100);

}

catch(Exception e)

{

}

}

}

}

InputNameTextField。java

import java.awt.*;

import java點(diǎn)虐 .*;

import java.awt.event.*;

import java.io.*;

import java.util.Hashtable;

public class InputNameTextField extends Panel implements ActionListener,Runnable

{

TextField nameFile=null;

String name=null;

Checkbox male=null,female=null;

CheckboxGroup group=null;

Button 進(jìn)入聊天室=null,退出聊天室=null;

Socket socket=null;

DataInputStream in=null;

DataOutputStream out=null;

Thread thread=null;

boolean 能否聊天=false;

Hashtable listTable;

public InputNameTextField(Hashtable listTable)

{

this.listTable=listTable;

nameFile=new TextField(10);

group=new CheckboxGroup();

male=new Checkbox("男",true,group);

female=new Checkbox("女",false,group);

進(jìn)入聊天室=new Button("進(jìn)入");

退出聊天室=new Button("退出");

進(jìn)入聊天室.addActionListener(this);

退出聊天室.addActionListener(this);

thread=new Thread(this);

add(new Label("昵稱:"));

add(nameFile);

add(male);

add(female);

add(進(jìn)入聊天室);

add(退出聊天室);

退出聊天室.setEnabled(false);

}

public void set能否聊天(boolean b)

{

能否聊天=b;

}

public boolean get能否聊天()

{

return 能否聊天;

}

public String getName()

{

return name;

}

public void setName(String s)

{

name=s;

}

public void setSocketConnection(Socket socket,DataInputStream in,DataOutputStream out)

{

this.socket=socket;

this.in=in;

this.out=out;

try{

thread.start();

}

catch(Exception e)

{

nameFile.setText(""+e);

}

}

public Socket getSocket()

{

return socket;

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==進(jìn)入聊天室)

{

退出聊天室.setEnabled(true);

if(能否聊天==true)

{

nameFile.setText("您正在聊天:"+name);

}

else

{

this.setName(nameFile.getText());

String sex=group.getSelectedCheckbox().getLabel();

if(socket!=nullname!=null)

{

try{

out.writeUTF("姓名:"+name+"性別:"+sex);

}

catch(IOException ee)

{

nameFile.setText("沒有連通服務(wù)器"+ee);

}

}

}

}

if(e.getSource()==退出聊天室)

{

try

{

out.writeUTF("用戶離開:");

}

catch(IOException ee)

{

}

}

}

public void run()

{

String message=null;

while(true)

{

if(in!=null)

{

try

{

message=in.readUTF();

}

catch(IOException e)

{

nameFile.setText("和服務(wù)器斷開"+e);

}

}

if(message.startsWith("可以聊天:"))

{

能否聊天=true;

break;

}

else if(message.startsWith("聊天者:"))

{

String people=message.substring(message.indexOf(":")+1);

listTable.put(people,people);

}

else if(message.startsWith("不可以聊天:"))

{

能否聊天=false;

nameFile.setText("該昵稱已被占用");

}

}

}

}

java 聊天室 源代碼

【ClientSocketDemo.java 客戶端Java源代碼】

import java點(diǎn)虐 .*;

import java.io.*;

public class ClientSocketDemo

{

//聲明客戶端Socket對(duì)象socket

Socket socket = null;

//聲明客戶器端數(shù)據(jù)輸入輸出流

DataInputStream in;

DataOutputStream out;

//聲明字符串?dāng)?shù)組對(duì)象response,用于存儲(chǔ)從服務(wù)器接收到的信息

String response[];

//執(zhí)行過程中,沒有參數(shù)時(shí)的構(gòu)造方法,本地服務(wù)器在本地,取默認(rèn)端口10745

public ClientSocketDemo()

{

try

{

//創(chuàng)建客戶端socket,服務(wù)器地址取本地,端口號(hào)為10745

socket = new Socket("localhost",10745);

//創(chuàng)建客戶端數(shù)據(jù)輸入輸出流,用于對(duì)服務(wù)器端發(fā)送或接收數(shù)據(jù)

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

//獲取客戶端地址及端口號(hào)

String ip = String.valueOf(socket.getLocalAddress());

String port = String.valueOf(socket.getLocalPort());

//向服務(wù)器發(fā)送數(shù)據(jù)

out.writeUTF("Hello Server.This connection is from client.");

out.writeUTF(ip);

out.writeUTF(port);

//從服務(wù)器接收數(shù)據(jù)

response = new String[3];

for (int i = 0; i response.length; i++)

{

response[i] = in.readUTF();

System.out.println(response[i]);

}

}

catch(UnknownHostException e){e.printStackTrace();}

catch(IOException e){e.printStackTrace();}

}

//執(zhí)行過程中,有一個(gè)參數(shù)時(shí)的構(gòu)造方法,參數(shù)指定服務(wù)器地址,取默認(rèn)端口10745

public ClientSocketDemo(String hostname)

{

try

{

//創(chuàng)建客戶端socket,hostname參數(shù)指定服務(wù)器地址,端口號(hào)為10745

socket = new Socket(hostname,10745);

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

String ip = String.valueOf(socket.getLocalAddress());

String port = String.valueOf(socket.getLocalPort());

out.writeUTF("Hello Server.This connection is from client.");

out.writeUTF(ip);

out.writeUTF(port);

response = new String[3];

for (int i = 0; i response.length; i++)

{

response[i] = in.readUTF();

System.out.println(response[i]);

}

}

catch(UnknownHostException e){e.printStackTrace();}

catch(IOException e){e.printStackTrace();}

}

//執(zhí)行過程中,有兩個(gè)個(gè)參數(shù)時(shí)的構(gòu)造方法,第一個(gè)參數(shù)hostname指定服務(wù)器地址

//第一個(gè)參數(shù)serverPort指定服務(wù)器端口號(hào)

public ClientSocketDemo(String hostname,String serverPort)

{

try

{

socket = new Socket(hostname,Integer.parseInt(serverPort));

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

String ip = String.valueOf(socket.getLocalAddress());

String port = String.valueOf(socket.getLocalPort());

out.writeUTF("Hello Server.This connection is from client.");

out.writeUTF(ip);

out.writeUTF(port);

response = new String[3];

for (int i = 0; i response.length; i++)

{

response[i] = in.readUTF();

System.out.println(response[i]);

}

}

catch(UnknownHostException e){e.printStackTrace();}

catch(IOException e){e.printStackTrace();}

}

public static void main(String[] args)

{

String comd[] = args;

if(comd.length == 0)

{

System.out.println("Use localhost(127.0.0.1) and default port");

ClientSocketDemo demo = new ClientSocketDemo();

}

else if(comd.length == 1)

{

System.out.println("Use default port");

ClientSocketDemo demo = new ClientSocketDemo(args[0]);

}

else if(comd.length == 2)

{

System.out.println("Hostname and port are named by user");

ClientSocketDemo demo = new ClientSocketDemo(args[0],args[1]);

}

else System.out.println("ERROR");

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

【ServerSocketDemo.java 服務(wù)器端Java源代碼】

import java點(diǎn)虐 .*;

import java.io.*;

public class ServerSocketDemo

{

//聲明ServerSocket類對(duì)象

ServerSocket serverSocket;

//聲明并初始化服務(wù)器端監(jiān)聽端口號(hào)常量

public static final int PORT = 10745;

//聲明服務(wù)器端數(shù)據(jù)輸入輸出流

DataInputStream in;

DataOutputStream out;

//聲明InetAddress類對(duì)象ip,用于獲取服務(wù)器地址及端口號(hào)等信息

InetAddress ip = null;

//聲明字符串?dāng)?shù)組對(duì)象request,用于存儲(chǔ)從客戶端發(fā)送來的信息

String request[];

public ServerSocketDemo()

{

request = new String[3]; //初始化字符串?dāng)?shù)組

try

{

//獲取本地服務(wù)器地址信息

ip = InetAddress.getLocalHost();

//以PORT為服務(wù)端口號(hào),創(chuàng)建serverSocket對(duì)象以監(jiān)聽該端口上的連接

serverSocket = new ServerSocket(PORT);

//創(chuàng)建Socket類的對(duì)象socket,用于保存連接到服務(wù)器的客戶端socket對(duì)象

Socket socket = serverSocket.accept();

System.out.println("This is server:"+String.valueOf(ip)+PORT);

//創(chuàng)建服務(wù)器端數(shù)據(jù)輸入輸出流,用于對(duì)客戶端接收或發(fā)送數(shù)據(jù)

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

//接收客戶端發(fā)送來的數(shù)據(jù)信息,并顯示

request[0] = in.readUTF();

request[1] = in.readUTF();

request[2] = in.readUTF();

System.out.println("Received messages form client is:");

System.out.println(request[0]);

System.out.println(request[1]);

System.out.println(request[2]);

//向客戶端發(fā)送數(shù)據(jù)

out.writeUTF("Hello client!");

out.writeUTF("Your ip is:"+request[1]);

out.writeUTF("Your port is:"+request[2]);

}

catch(IOException e){e.printStackTrace();}

}

public static void main(String[] args)

{

ServerSocketDemo demo = new ServerSocketDemo();

}

}


當(dāng)前題目:java安卓聊天室源代碼 java聊天室實(shí)現(xiàn)原理
文章來源:http://weahome.cn/article/ddjsdhc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部