当前位置:网站首页>105. 简易聊天室8:使用 Socket 传递图片
105. 简易聊天室8:使用 Socket 传递图片
2022-06-24 12:33:00 【Jasonakeke】
题目描述
题目实现:使用网络编程时,需要通过 Socket 传递图片。
解题思路
创建一个服务器类:ServerSocketFrame,继承 JFrame 类
写一个 getServer() 方法,实例化Socket对象,启用9527当服务的端口。
创建输入流对象,用来接收客户端信息。
再定义一个 getClientInfo() 方法,用于接收客户端发送的信息。
对文本框添加一个事件:实现向客户端发磅信息。
创建一个客户端类:ClientSocketFrame,继承 JFrame 类。
写一个 connect() 方法,实例化 Socket 对象,连接本地服务的9527端口服务。
再定义一个 getClientInfo() 方法,用于接收服务端发送的信息。
技术重点:
通过使用 DataInputStream 类的 read() 方法,将图片文件读取到字节数组,然后使用 DataOutputStream 类从 DataOutput 类继承的 write() 方法输出字节数组,从而实现了使用 Socket 传输图片的功能。
代码详解
边栏推荐
- 基于AM335X开发板 ARM Cortex-A8——Acontis EtherCAT主站开发案例
- Install MySQL in docker and modify my CNF profile
- pipeline groovy
- National standard platform easygbs administrator assigns roles to sub users and troubleshooting of invalid channels
- 11+! Methylation modification patterns based on m6A regulatory factors in colon cancer are characterized by different tumor microenvironment immune spectra
- [live review] battle code pioneer phase 7: how third-party application developers contribute to open source
- Deep parsing and implementation of redis pub/sub publish subscribe mode message queue
- How to evaluate software development projects reasonably?
- GLOG from getting started to getting started
- LS-DYNA新手入门经验
猜你喜欢

How to write controller layer code gracefully?

How is the e-commerce red envelope realized? For interview (typical high concurrency)

GTEST from getting started to getting started

Linker --- linker

Insurance app aging service evaluation analysis 2022 issue 06

Opencv learning notes - regions of interest (ROI) and image blending
Database migration tool flyway vs liquibase (II)

Opencv learning notes - loading and saving images

Install Kali on the U disk and persist it
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!
随机推荐
pipeline groovy
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!
The idea of "6 points + gene family" without experiment~
Kubernetes practical technique: setting kernel parameters for pod
What are the low threshold financial products in 2022? Not much money
11+文章-机器学习打造ProTICS框架-深度揭示了不同分子亚型中肿瘤浸润免疫细胞对预后的影响
单基因泛癌+简单实验就能发表7分+
Which commercial insurance endowment insurance is good? Ranking of commercial endowment insurance products in 2022
Example of SMS interface verification code function implemented by ThinkPHP framework
Practice of dynamic load balancing based on open source tars
National standard platform easygbs administrator assigns roles to sub users and troubleshooting of invalid channels
Flink snapshot analysis: operators for locating large states and data skew
How to purchase new bonds is it safe to open an account
Is it safe to open an account for how many new bonds you can apply for
Difference between X12 830 and 862 messages
How to make Baidu quickly include its own personal website?
打新债的条件 开户是安全的吗
怎样打新债具体操作 开户是安全的吗
Process of solving easydss virtual live video jam and instability problems by replacing push-pull stream Library
Group planning - General Review