8000 You can set the local binded port · SaffronCode/SaffronCode@f06664c · GitHub
[go: up one dir, main page]

Skip to content

Commit f06664c

Browse files
committed
You can set the local binded port
1 parent a220a8e commit f06664c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

netManager/UDPManager.as

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ package netManager
2727
onReceiveFunction(message)
2828
}
2929

30-
private static function getMessageOnPort(onRespond:Function,myPort:uint=43243):void
30+
private static function getMessageOnPort(onRespond:Function,myPort:uint):void
3131
{
3232
trace("myUDP.connected : "+myUDP.connected);
3333
trace("myUDP.localPort : " +myUDP.localPort);
3434
onReceiveFunction = onRespond ;
35-
if(myUDP.localPort==0 || ( myUDP.localPort!=myPort && myPort!=43243))
35+
if(myUDP.localPort==0 || ( myUDP.localPort!=myPort))
3636
{
3737
if(myUDP.connected)
3838
myUDP.close();
@@ -42,11 +42,16 @@ package netManager
4242
}
4343
}
4444

45-
public static function sendMessageTo(message:String,onRespond:Function,targetIp:String,targetPort:uint):void
45+
public static function isConnected():Boolean
46+
{
47+
return myUDP.connected && myUDP.localPort !=0;
48+
}
49+
50+
public static function sendMessageTo(message:String,onRespond:Function,targetIp:String,targetPort:uint,localPort:uint=2000):void
4651
{
4752
setUp();
4853
trace("Message sent:"+message);
49-
getMessageOnPort(onRespond);
54+
getMessageOnPort(onRespond,localPort);
5055
var data:ByteArray = new ByteArray();
5156
data.writeUTFBytes(message);
5257
myUDP.send(data,0,0,targetIp,targetPort);