https://www.myziyuan.com/
- wolf8668
- 最简单的asp聊天室代码 <%@ Language=VBScript %><%Response.Buffer=true ' 设 置 输 出 缓 存,用 于 显 示 不 同 页 面。On error resume next ' 忽 略 程 序 出 错 部 分If Request.ServerVariables("Request_Method")="GET" then' 判 断 客 户 是 以 什 么 方 式 请 求 WEB 页 面'------------------------' 客 户 登 陆 界 面'------------------------%> <form method="POST" action="call.asp"><p><input type="text" name="nick" size="20" value="nick" style="background-color: rgb(192,192,192)"><input type="submit" value=" 进 入 聊 天 室 " name="B1" style="color: rgb(255,255,0); font-size: 9pt; background-color: rgb(0,128,128)"><p><input type="hidden" name="log" size="20" value="1"></p></form> <%Response.End ' 结 束 程 序 的 处 理ElseResponse.clear ' 清 空 缓 存 中 的 内 容dim talkIf Request.Form("nick")<>"" then' 判 断 客 户 是 是 否 在 聊 天 界 面 中Session("nick")=Request.Form("nick")End If'------------------------'客 户 聊 天 界 面'------------------------%> <form method="POST" action="call.asp" name=form1> <p><%=Session("nick")%> 说 话:<input type="text" name="talk" size="50"><input type="submit" value=" 提 交 " name="B1"><input type="reset" value=" 取 消 " name="B2"></p></form><A href="/blog/untitled.asp"> 离 开 </a> <%If Request.Form("log")<>1 thenIf trim(Request.Form("talk"))="" then' 判 断 用 户 是 否 没 有 输 入 任 何 内 容talk=Session("nick")&" 沉 默 是 金。"Elsetalk=trim(Request.Form("talk"))' 去 掉 字 符 后 的 空 格End If Application.lockApplication("show")="<table border='0' cellpadding='0' cellspacing='0' width='85%'><tr><td width='100%' bgcolor='#C0C0C0'></td></tr><tr><td width='100%'><font color='#0000FF'> 来 自 "&Request.ServerVariables("remote_addr")&" 的 "&Session("nick")&time&" 说:</font>"&talk&"</td></tr><tr><td width='100%' bgcolor='#C0C0C0'></td></tr></table>"&Application("show")Application.UnLock Response.Write Application("show")End IfEnd If%>
- 2021-02-19 13:55:20
- 11212121
- 【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(); }}
- 2021-02-11 16:18:47
- 售微星二开源码
- 急求java聊天室源代码! 分数全部送上!,//登录聊天室 public void login(){ if(loggedIn) return; try{ sock=new Socket(getCodeBase().getHost(),port); is=new BufferedReader(new InputStreamReader(sock.getInputStream())); pw=new PrintWriter(sock.getOutputStream(),true); }catch(IOException e){ showStatus("Can't get socket: "+e); cp.add(new Label("Can't get socket: "+e)); return;} //构造并且启动读入器,从服务器读取数据,输出到文本框中 //这里,长成一个线程来避免锁住资源(lockups) new Thread (new Runnable(){ public void run(){ String line; try{ while(loggedIn &&((line=is.readLine())!=null)) ta.appendText(line+"\n"); }catch(IOException e){ showStatus("我的天啊,掉线了也!!!!"); return;
- 2021-02-11 16:18:47