Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the actual operation of Java Socket communication?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I will talk to you about the actual operation of Java Socket communication, many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Java Socket communication has a lot of things we need to pay attention to when we actually use it. So first of all, let's look at how Java Socket communication is prepared and how to establish a connection in practice. I hope you all get something.

First, prepare:

Server: JDK1.5 (no need to introduce this, right? )

Server IDE:eclipse (its home page)

Client: FLEX 3 (Adobe ®Flex ®3) is an efficient open source framework for building and maintaining expressive Web applications deployed consistently on all major browsers, desktops, and operating systems. )

Client IDE:Flex Builder 3 (its official summary page)

Second, the encounter of fate (establishing a connection):

Since it is a communication, of course, the step is to establish a connection. Let's start our connection with the easiest way to look at the code.

Server code: Jserver1.java

Java code

Import java.net.*

Import java.io.*

Public class Jserver1 {

Public static void main (String [] args) {

ServerSocket server=null

Try {

Server=new ServerSocket / / create a server socket object on port 719

System.out.println ("server waiting")

While (true) {

System.out.println ("waiting for the client")

Socket newSocket=server.accept (); / / the server set up by the client to us

If a connection request is sent by a connector, it will be executed down.

System.out.println ("connected to client")

}

} catch (IOException ie)

{

System.out.println (ie)

} finally {

Try

{

If (server socket null) server.close (); / / closes the server socket. Why do you use it?

Finally keyword to do this? The master in HOHO thinking in java has already

To make it clear, no matter what happens, our server-side sockets are guaranteed to be turned off.

} catch (IOException ie) {}

}

}

After reading the above, do you have any further understanding of the actual operation of Java Socket communication? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report