current position:Home>105. simple chat room 8: use socket to transfer pictures

105. simple chat room 8: use socket to transfer pictures

2022-06-24 12:38:40Jasonakeke

Title Description

Topic realization : When using network programming , Need to pass through Socket Pass on the pictures .

Their thinking

Create a server class :ServerSocketFrame, Inherit JFrame class

Write a getServer() Method , Instantiation Socket object , Enable 9527 When the port of the service .

Create an input stream object , Used to receive client information .

Let me define one more getClientInfo() Method , Used to receive information sent by the client .

Add an event to the text box : Realize sending weighing information to the client .

Create a client class :ClientSocketFrame, Inherit JFrame class .

Write a connect() Method , Instantiation Socket object , Connect to the local service 9527 Port services .

Let me define one more getClientInfo() Method , Used to receive information sent by the server .

Technical focus :

By using DataInputStream Class read() Method , Read image file into byte array , And then use DataOutputStream Class from DataOutput Class inheritance write() Method to output an array of bytes , Thus, the use of Socket The function of transferring pictures .

Code details

copyright notice
author[Jasonakeke],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/175/202206241031041660.html

Random recommended