Solve the socket security policy file problem of Flash AS3 with Golang

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The code is as follows:

</pre><pre>package mainimport ("Bufio" "FMT" "NET" "OS" "Time") const (Head = 4) var (clientmap map[int]net. Conn = Make (map[int]net. Conn)) Func main () {FMT. Println (OS. Args[0]) Ip_port: = "127.0.0.1:843" If Len (OS. Args) > 1 {ip_port = OS. Args[1]}fmt. Println ("\nflash as policy service running ... \ n" automatically responds to crossdomain.xml requests for socketxml ports (i.e. 843 ports) \ n to specify the IP and port, you can specify the parameters when the program starts, in the following format \ Ngameserver843.exe 192.168.101.139:843 "," \ n currently listening ", Ip_port," \ n please do not close this window ... ") tcpaddr, err: = Net. RESOLVETCPADDR ("TCP4", Ip_port) checkerror (ERR) listener, err: = Net. LISTENTCP ("TCP", TCPADDR) checkerror (err) Clientindex: = 0for {clientindex++conn, err: = Listener. Accept () if err! = Nil {Continue}go handleclient (conn, clientindex)}}func handleclient (conn net. Conn, index int) {Clientmap[index] = connfmt. Println ("") fmt. Println ("=======================") fmt. PRINTLN ("New user connection, from:", Conn.) Remoteaddr (), "Index:", index) FC: = Func () {time. Sleep (time. Second)//give the client 1 seconds of response time, otherwise the client may not be able to read the data in advance Close the Conn.close () Delete (Clientmap, index) FMT. PRINTLN ("Remove serial number as:", Index," client, disconnects the client ") FMT. Println ("=======================")}defer FC () SENDFIRSTMSG (conn)}func SENDFIRSTMSG (conn net. Conn) {str: = ' <?xml version= ' 1.0 '? ><! DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd" ><cross-domain-policy>< Site-control permitted-cross-domain-policies= "master-only"/><allow-access-from domain= "*" to-ports= "*"/> </cross-domain-policy> ' Writer: = Bufio. Newwriter (conn) writer. WriteString (str) writer. Flush () fmt. Println ("Already responded policy file: Crossdomain.xml")}func checkerror (err error) {if err! = Nil {fmt. Println (Err. Error ()) OS. Exit (1)}}


Install the Golang environment, then go directly to run Main.go on the line.

Of course, you can also download my compiled exe executable file directly.

The download page is as follows:

https://github.com/moketao/XmlSocket_843

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.