@@ -27,12 +27,12 @@ package netManager
27
27
onReceiveFunction(message )
28
28
}
29
29
30
- private static function getMessageOnPort (onRespond :Function ,myPort :uint = 43243 ):void
30
+ private static function getMessageOnPort (onRespond :Function ,myPort :uint ):void
31
31
{
32
32
trace ("myUDP.connected : " + myUDP. connected );
33
33
trace ("myUDP.localPort : " + myUDP. localPort);
34
34
onReceiveFunction = onRespond ;
35
- if (myUDP. localPort== 0 || ( myUDP. localPort!= myPort && myPort != 43243 ))
35
+ if (myUDP. localPort== 0 || ( myUDP. localPort!= myPort))
36
36
{
37
37
if (myUDP. connected )
38
38
myUDP. close ();
@@ -42,11 +42,16 @@ package netManager
42
42
}
43
43
}
44
44
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
46
51
{
47
52
setUp();
48
53
trace ("Message sent:" + message );
49
- getMessageOnPort(onRespond);
54
+ getMessageOnPort(onRespond,localPort );
50
55
var data : ByteArray = new ByteArray ();
51
56
data . writeUTFBytes (message );
52
57
myUDP. send (data ,0 ,0 ,targetIp,targetPort);
0 commit comments