gpt4 book ai didi

c# - AS3 客户端套接字无法连接到本地网络服务器

转载 作者:太空宇宙 更新时间:2023-11-03 13:23:11 26 4
gpt4 key购买 nike

我在一台 PC 上有一个 c# 服务器套接字,在与第一台 PC 位于同一本地网络的另一台 PC 上有一个客户端 AS3 套接字。问题是当 c# 和 AS3 在同一台 PC 上时,连接正常,但是当我在本地网络上的另一台 PC 上移动 c# 时,AS3 无法访问它!!

最佳答案

请引用下面给出的代码:

package {
import flash.display.Sprite;

public class SocketExample extends Sprite {
private var socket:CustomSocket;

public function SocketExample() {
socket = new CustomSocket("localhost", 80);
}
}
}

import flash.errors.*;
import flash.events.*;
import flash.net.Socket;

class CustomSocket extends Socket {
private var response:String;

public function CustomSocket(host:String = null, port:uint = 0) {
super();
configureListeners();
if (host && port) {
super.connect(host, port);
}
}

private function configureListeners():void {
addEventListener(Event.CLOSE, closeHandler);
addEventListener(Event.CONNECT, connectHandler);
addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
}

private function writeln(str:String):void {
str += "\n";
try {
writeUTFBytes(str);
}
catch(e:IOError) {
trace(e);
}
}

private function sendRequest():void {
trace("sendRequest");
response = "";
writeln("GET /");
flush();
}

private function readResponse():void {
var str:String = readUTFBytes(bytesAvailable);
response += str;
}

private function closeHandler(event:Event):void {
trace("closeHandler: " + event);
trace(response.toString());
}

private function connectHandler(event:Event):void {
trace("connectHandler: " + event);
sendRequest();
}

private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}

private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}

private function socketDataHandler(event:ProgressEvent):void {
trace("socketDataHandler: " + event);
readResponse();
}
}

关于c# - AS3 客户端套接字无法连接到本地网络服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23417881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com