# ComputerNetworking-OnlineChatting **Repository Path**: qunshanhe/computer-networking-online-chatting ## Basic Information - **Project Name**: ComputerNetworking-OnlineChatting - **Description**: 计算机网络Socket网络编程实现TCP&UDP在线聊天。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2020-11-26 - **Last Updated**: 2020-12-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ComputerNetworking-OnlineChatting ## 文件功能介绍 |NetBeans项目文件夹|功能| | ------- | ------ | |SocketChatting| 基于TCP的Socket网络聊天 | |UDPChatting| 基于UDP的DatagramSocket网络聊天 | ## 介绍 计算机网络Socket网络编程实现TCP&UDP在线聊天。TCP及UDP是工作于计算机网络传输层的协议,而Socket则是TCP及UDP网络连接实现的桥梁。 ### TCP(Transmission Control Protocol) TCP是一种面向连接的、可靠的、基于字节流的传输层通信协议。 ### UDP(User Datagram Protocol): UDP是一个无连接的、快速有效的传输层通信协议。 ## SocketChatting 实现了Server类及Client类,主类为SocketChat,连接方式为本地客户机<-->目标服务器,本地服务器<-->对方客户机,通信双方客户机连接对方服务器,客户机负责从键盘读取消息并发送给对方服务器,服务器负责接收对方的消息并显示。 这里实现了聊天带昵称、发送时间、主动终止对话等功能。 ### 运行本项目,需要先配置目的主机的IP地址及端口号, ```java // 指定本地服务器端口号为19888 new Thread(new Server(new ServerSocket(19888))).start(); Thread.sleep(5000); // 指定目标服务器IP为10.151.14.15 端口号为19888 昵称为Mountain new Thread(new Client(new Socket("10.151.14.15",19888),"Mountain")).start(); ``` ## UDPChatting 实现了Server类及Client类,主类为SocketChat,连接方式为本地客户机-->目标服务器,本地服务器<--对方客户机。 ### 运行本项目,需要先配置目的主机的IP地址及端口号, ```java // 指定本地服务器端口号为19888 new Thread(new Server(19888)).start(); // 指定目标服务器IP为10.151.14.15,端口号为19888 new Thread(new Client(19887,"10.151.14.15",19888)).start(); ``` ## 查询本地IP ### Windows cmd ``` ipconfig ``` ### Linux Terminal ``` ifconfig ```