当前位置:网站首页>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 传输图片的功能。
代码详解
边栏推荐
- How do websites and we media tap user needs? Deeply expose the secrets behind the keywords!
- Discussion on redis communication protocol
- 12+!不同癌症中TMB与ICI反应之间的免疫相关因素研究
- 11+文章-机器学习打造ProTICS框架-深度揭示了不同分子亚型中肿瘤浸润免疫细胞对预后的影响
- Hardware enterprise website ranking, 8 commonly used processes
- Which commercial insurance endowment insurance is good? Ranking of commercial endowment insurance products in 2022
- Getting started with scrapy
- Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!
- Group planning - General Review
- GTEST from getting started to getting started
猜你喜欢

Linker --- linker

How can a shell script (.Sh file) not automatically close or flash back after execution?

Insurance app aging service evaluation analysis 2022 issue 06

Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!
![[live review] battle code pioneer phase 7: how third-party application developers contribute to open source](/img/fa/e52bd8a1a404a759ef6ba88e8da0f0.png)
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source
Database migration tool flyway vs liquibase (II)

GLOG from getting started to getting started

How to write controller layer code gracefully?

Install Kali on the U disk and persist it

文本转语音功能上线,可以体验专业播音员的服务,诚邀试用
随机推荐
Pipeline shared library
Kubernetes practical technique: setting kernel parameters for pod
As one of the bat, what open source projects does Tencent have?
Speculation London gold short-term stable money making skills? Where is it safe to fry London gold?
JVM GC garbage collection detailed introduction quick check of learning notes
Based on am335x development board arm cortex-a8 -- acontis EtherCAT master station development case
RTMP streaming platform easydss video on demand interface search bar development label fuzzy query process introduction
What are the software prototyping tools?
Tencent security monthly report - zero trust development trend forum, digital Expo Technology Award, Mercedes Benz security research results
What are the low threshold financial products in 2022? Not much money
mRNA疫苗的研制怎么做?27+ 胰腺癌抗原和免疫亚型的解析来告诉你答案!
How to check the situation that the national standard platform easygbs equipment video cannot be accessed by grabbing packets?
5分+的单基因泛癌纯生信思路!
The idea of "6 points + gene family" without experiment~
Difference between X12 830 and 862 messages
[2021 techo youth dry goods sorting post, there is always one you are interested in]
Node cache vs browser cache
11+文章-机器学习打造ProTICS框架-深度揭示了不同分子亚型中肿瘤浸润免疫细胞对预后的影响
Do you really know "open source"? Please check [nanny level] open source Encyclopedia
How does easygbs, a national standard platform, solve the problem that information cannot be carried across domains?