当前位置:网站首页>103. simple chat room 6: using socket communication

103. simple chat room 6: using socket communication

2022-06-22 04:25:00 Jasonakeke

Title Description

Topic realization : Socket is used to realize the communication between server and client .

Run the program , Enter information in the server-side text box , Then press enter , The client will receive the information sent by the server ;

Enter information in the client's text box , Then press enter , The server will receive the information sent by the client , Effect after sending information .

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 :

adopt Socket Class getInpuStream() Method to get the input stream object , With the help of InputStream

原网站

版权声明
本文为[Jasonakeke]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220424386026.html