In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to connect Flex to .NET Socket-based networks. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Socket-based Network connection between Flex and .NET
Flash/Flex also supports Socket-based network connections, and the server side can be developed in any language such as Clipper, VB, Magi, Java, etc. Listen to a network port to receive connections from clients developed by Flash/Flex.
ActionScript3.0 provides a way to communicate with the server over a Socket connection. This is an important feature that goes beyond the traditional Bhand S structure. In this way, the network communication can be connected immediately, which avoids the disadvantage of stateless connection of HTTP protocol. ActionScript3.0 uses the XMLSocket class to connect. It is important to note that when you use the XMLSocket class for Socket connections, you cannot automatically traverse the firewall. To connect through a firewall, you need to use the RTMP protocol based on the HTTP protocol.
By referring to the API documentation provided by Adobe, you can see that XMLSocket provides four public methods:
1. XMLSocket (host:String=null,port:int=0)-- create a new XMLSocket object.
2. Close (): void-- closes a XMLSocket.
3. Connect (host:String,port:int): void-- connects to the specified TCP port.
4. Send (object:*): void-- sends data to the connection server.
OK, after knowing these, we can use XMLSocket to develop network and timely communication applications based on Socket. The following provides a Socket server through C# and listens to port 8888. The example program is as follows:
1usingsystem; 2usingSystem.Collections.Generic3usingSystem.Linq; 4usingSystem.Text; 5usingSystem.Net.Sockets6usingSystem.IO; 7 8namespaceFlashFlexDotNet 9 {10classProgram 11 {12staticvoidMain (string [] args) 13 {14TcpListenerlistener15 16try 17 {18listener=newTcpListener (8888); 19} SystemListenerlistener15} System21 {22Console.WriteLine (ex.Message); 23server; 24} 25 26listener.Start (); 27Console.WriteLine ("server starts, waiting for client connection."); 28boolloop=true 29 30while (loop) 31 {32Sockets=listener.AcceptSocket (); 33NetworkStreamns=newNetworkStream (s); 34StreamReaderreader=newStreamReader (ns); 35 stringresultstringEmpty37 {38result=reader.ReadLine (); 39Console.WriteLine (result); 40} 41catch (Exceptionex) 42 {43Console.WriteLine (ex.Message); 44} 45} 46} 47} 48} 49
Now that the ◆ server-side Socket is ready, let's see how the XMLSocket of the client-side ActionScript can establish a Socket connection to communicate with the. Net Socket server.
As described earlier in this article, ActionScript3.0 provides a Socket-based network connection class XMLSocket
We can use it directly to develop network communication based on Socket. Establish a network connection to the XMLSocket provided by ActionScript3.0 as follows:
1privatefunctionconnectionServer (): void 2 {3xmlConn=newXMLSocket (); 4xmlConn.connect ("127.0.0.1", 8888); 5} you can then send messages to the Socket server through the XMLSocket instance method send (). The code definition is as follows: 1privatefunctiononSend (): void 2 {3xmlConn.send (txtData.text+ "\ n"); 4}
Complete client code:
1 25 6 22 23 24 25 26 Thank you for reading! This is the end of the article on "how to realize the Socket-based network connection between Flex and .NET". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.