用户登录
用户注册

分享至

聊天软件代码 聊天室代码的应用方法

  • 作者: 总有刁民想睡俺
  • 来源: 51数据库
  • 2020-04-17

比如你聊天室首页的文件是123.asp 和你网页是同目录

在你网页上面的文字上面点右键

然后有个超链接

选择路径的时候填写http://**********(你的域名)/123.asp

或者123.asp是在同目录下的321文件夹里

那就是http://**********(你的域名)/321/123.asp

java 聊天室代码???

前天帮人解决过,代码如下:public class iChat extends JFrame {

private JPanel jContentPane;

private JButton jButton1;

private JScrollPane jScrollPane1;

private JTextArea jTextArea1,jTextArea2; public iChat() {

super();

initialize();

} private void initialize() {

this.setSize(375, 364);

jTextArea1 = getJTextArea1();

this.setContentPane(getJContentPane());

this.setTitle("聊天室");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private JPanel getJContentPane() {

if (jContentPane == null) {

jContentPane = new JPanel();

jContentPane.setBackground(Color.BLUE);//蓝色为JPanel 。

jContentPane.setLayout(null);

jContentPane.add(getJButton1(), null);

jContentPane.add(getJTextArea2(), null);

jContentPane.add(getJScrollPane1(), null);

}

return jContentPane;

} private JTextArea getJTextArea2() {

if (jTextArea2 == null) {

jTextArea2 = new JTextArea();

jTextArea2.setBounds(new Rectangle(1, 253, 282, 73));

jTextArea2.setLineWrap(true);

jTextArea2.addKeyListener(new java.awt.event.KeyAdapter() {

public void keyTyped(java.awt.event.KeyEvent e) {

if (e.getKeyChar() == KeyEvent.VK_ENTER) {

String s = "你说:" + jTextArea2.getText();

String date = new SimpleDateFormat(

"yyyy-MM-dd HH:mm:ss").format(Calendar

.getInstance().getTime());

jTextArea1.append(date + "\n");

jTextArea1.append(s);

}

}

});

}

return jTextArea2;

} private JButton getJButton1() {

if (jButton1 == null) {

jButton1 = new JButton();

jButton1.setBounds(new Rectangle(293, 288, 62, 32));

jButton1.setText("发送");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

String s = "你说:" + jTextArea2.getText();

String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

.format(Calendar.getInstance().getTime());

jTextArea1.append(date + "\n");

jTextArea1.append(s + "\n");

jTextArea2.setText(""); }

});

}

return jButton1;

}

private JScrollPane getJScrollPane1() {

if (jScrollPane1 == null) {

jScrollPane1 = new JScrollPane();

jScrollPane1.setBounds(new Rectangle(0, 0, 360, 220));

jScrollPane1.setViewportView(getJTextArea1());

}

return jScrollPane1;

} private JTextArea getJTextArea1() {

if (jTextArea1 == null) {

jTextArea1 = new JTextArea();

jTextArea1.setEditable(false);

jTextArea1.setLineWrap(true);

}

return jTextArea1;

} public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

iChat thisClass = new iChat();

thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

thisClass.setVisible(true);

}

});

}}

聊天软件代码 聊天室代码的应用方法

急求一个简易聊天室的代码

<html>

<head>

<title>小小聊天室</title>

</head>

<%

Session("user_name")=Request("user_name") '将用户昵称保存到session中

'下面几句返回来访者信息

Dim sayStr

sayStr="来自" & Request.ServerVariables("Remote_Addr")& "的" '来访者IP地址

sayStr=sayStr & "<b>" & Session("user_name") & "</b>" '来访者昵称

sayStr=sayStr & "于" & Time & "大驾光临" '来访时间

sayStr="<font color='red'>" & sayStr & "</font>" '红色显示

'下面几句将来访信息保存到Application中

Application.Lock '先锁定

Application("show")= sayStr & "<br>" & Application("show") '返回聊天信息

Application("user_online")=Application("user_online")+1 '在线人数加1 Application.Unlock '解除锁定

%>

<frameset rows="*,14%">

<frame name="main" src="main.asp" >

<frame name="input" src="input.asp">

<noframes>

<body scroll="no">

<p>此网页使用了框架,但您的浏览器不支持框架。</p>

</body>

</noframes>

</frameset>

</html>

**********************以上为CHAT.ASP****************

<%

'下面几句返回离开者信息

Dim sayStr

sayStr="来自" & Request.ServerVariables("Remote_Addr")& "的" '来访者IP地址

sayStr=sayStr & "<b>" & Session("user_name") & "</b>" '来访者昵称

sayStr=sayStr & "于" & Time & "高兴而去" '离开时间

sayStr="<font color='red'>" & sayStr & "</font>" '红色显示

'下面几句将来访信息保存到application中

Application.Lock '先锁定

Application("show")= sayStr & "<br>" & Application("show")

Application("user_online")=Application("user_online")-1 '在线人数减1

Application.Unlock '解除锁定

Response.Redirect "index.asp" '重定向回首页

%>

******以上为exit.asp****************

<html>

<head>

<title>聊天室</title>

<Script Language="JavaScript">

<!--

function check_Null(){

if (document.form1.user_name.value==""){

alert("昵称不能为空!");

return false;

}

return true;

}

// -->

</Script>

</head>

<body >

<h2 align="center">小小聊天室</h2>

<center>

现在共有<%=Application("user_online")%>人在线<p>

<form method="post" action="chat.asp" name="form1" onsubmit="JavaScript: return check_Null();">

请输入昵称<input type="text" name="user_name" size="10">

<input type="submit" value=" 进 入 ">

</form>

</center>

</body>

</html>

************以上为index.asp*******************

<html>

<head>

<title>发言区</title>

</head>

<body bgcolor="#FFFFCC" topmargin="0" leftmargin="0" onload="document.form1.say.focus();">

<form method="post" action="" name="form1">

发言:

<input type="text" name="say" size=40 >

<input type="submit" value="发言" >

<br>

颜色:

<select name="mycolor" style="font-size:12px">

<% If Request("mycolor")="#000000" Then %>

<option value="#000000" style="color:#000000" selected>黑色</option>

<% Else %>

<option value="#000000" style="color:#000000" >黑色</option>

<% End If %>

<% If Request("mycolor")="#FF0000" Then %>

<option value="#FF0000" style="color:#FF0000" selected>红色</option>

<% Else %>

<option value="#FF0000" style="color:#FF0000" >红色</option>

<% End If %>

<% If Request("mycolor")="#FFFF00" Then %>

<option value="#FFFF00" style="color:#FFFF00" selected>黄色</option>

<% Else %>

<option value="#FFFF00" style="color:#FFFF00" >黄色</option>

<% End If %>

<% If Request("mycolor")="#3333FF" Then %>

<option value="#3333FF" style="color:#3333FF" selected>蓝色</option>

<% Else %>

<option value="#3333FF" style="color:#3333FF" >蓝色</option>

<% End If %>

</select>

表情:

<select name="myemote" style="font-size:12px">

<option value="无" selected>无

<option value="回眸一笑">回眸一笑

<option value="幸灾乐祸">幸灾乐祸

<option value="号啕大哭">号啕大哭

<option value="拳打脚踢">拳打脚踢

<option value="气急败坏">气急败坏

<option value="温柔细语">温柔细语

<option value="得意非凡">得意非凡

<option value="大惊失色">大惊失色

</select>

<a href="exit.asp" target="_top">离开聊天室</a>

</form>

<%

IF Request("say")<>"" Then

'获取发言的有关信息

Dim say,mycolor,myemote,user_name '声明变量待用

user_name=Session("user_name") '返回用户昵称

say=Server.HtmlEncode(Request("say")) '返回发言,并用HtmlEncode编码

mycolor=Request("mycolor") '返回本次发言的颜色

myemote=Request("myemote") '返回本次发言表情

If myemote="无" Then

myemote=""

End If

'下面三句将得到本次发言的字符串

Dim sayStr

sayStr="<small>" & user_name & Time & myemote & "说:</small>"

sayStr=sayStr & "<font color='" & mycolor & "'>" & say & "</font>"

'下面几句将本次发言信息保存到Application中

Application.Lock '先锁定

Application("show")= sayStr & "<br>" & Application("show")

If Len(Application("show"))>10000 Then '如果发言总长度超过10000个字符,则截断为10000

Application("show")=Mid(Application("show"),1,10000)

End If

Application.Unlock '解除锁定

End If

%>

</body>

</html>

**************以上为input.asp***************

<html>

<head>

<title> 发言区</title>

<meta http-equiv="refresh" content="5">

</head>

<body>

<%

Response.Write Application("show") '显示聊天内容

%>

</body>

</html>

************以上为main.asp***************

参考资料:http://www.downcode.com/downcode/j_10922_6b6790b4.shtml

HTML格式的聊天室代码

可以借助AJAX来实现

高分求解聊天室代码

你贴的不全。。有一些引用都不知道从来哪的。不过按照一般的编程逻辑还是能理解大概意思的

Application("chat_sd")是一个服务器级的变量。。for是在通过循环来算出子线人数什么的。。

你帖的这段代码主要实现的功能就是通过Application来记录在线人数,显示新会员等。。

晕。。。。这个问题你该问问代码编写人。没写变量备注吗??你贴的又是部分代码。能力有限,看不出来

java 聊天室 源代码

【ClientSocketDemo.java 客户端Java源代码】

import java.net.*;

import java.io.*;

public class ClientSocketDemo

{

//声明客户端Socket对象socket

Socket socket = null;

//声明客户器端数据输入输出流

DataInputStream in;

DataOutputStream out;

//声明字符串数组对象response,用于存储从服务器接收到的信息

String response[];

//执行过程中,没有参数时的构造方法,本地服务器在本地,取默认端口10745

public ClientSocketDemo()

{

try

{

//创建客户端socket,服务器地址取本地,端口号为10745

socket = new Socket("localhost",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();}

}

//执行过程中,有一个参数时的构造方法,参数指定服务器地址,取默认端口10745

public ClientSocketDemo(String hostname)

{

try

{

//创建客户端socket,hostname参数指定服务器地址,端口号为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();}

}

//执行过程中,有两个个参数时的构造方法,第一个参数hostname指定服务器地址

//第一个参数serverPort指定服务器端口号

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 服务器端Java源代码】

import java.net.*;

import java.io.*;

public class ServerSocketDemo

{

//声明ServerSocket类对象

ServerSocket serverSocket;

//声明并初始化服务器端监听端口号常量

public static final int PORT = 10745;

//声明服务器端数据输入输出流

DataInputStream in;

DataOutputStream out;

//声明InetAddress类对象ip,用于获取服务器地址及端口号等信息

InetAddress ip = null;

//声明字符串数组对象request,用于存储从客户端发送来的信息

String request[];

public ServerSocketDemo()

{

request = new String[3]; //初始化字符串数组

try

{

//获取本地服务器地址信息

ip = InetAddress.getLocalHost();

//以PORT为服务端口号,创建serverSocket对象以监听该端口上的连接

serverSocket = new ServerSocket(PORT);

//创建Socket类的对象socket,用于保存连接到服务器的客户端socket对象

Socket socket = serverSocket.accept();

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

//创建服务器端数据输入输出流,用于对客户端接收或发送数据

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

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

//接收客户端发送来的数据信息,并显示

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]);

//向客户端发送数据

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();

}

}

求QQ聊天室的管理代码

管理指令

//op forbid QQ号 (添加黑名单)

//op unforbid QQ号(解除黑名单)

//op wc QQ号 (关入小黑屋)

//op unwc QQ号(拎出小黑屋)

//op open QQ号 (解嘴) 对着聊天窗口 然后发送!

//op close QQ号(封封)

转载请注明出处51数据库 » 聊天软件代码 聊天室代码的应用方法

软件
前端设计
程序设计
Java相关