Browse Source

fixed to complitable and bind udp port to send data

master
jkpete 2 months ago
parent
commit
ea6b0023a7
  1. 1
      Font/SourceHanSansCN-Regular.otf.import
  2. 27
      addons/EGFramework/Module/ProtocolTools/EGUDP.cs
  3. 1
      project.godot

1
Font/SourceHanSansCN-Regular.otf.import

@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/SourceHanSansCN-Regular.otf-a74baadd242fcbfb4 @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/SourceHanSansCN-Regular.otf-a74baadd242fcbfb4
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48

27
addons/EGFramework/Module/ProtocolTools/EGUDP.cs

@ -1,10 +1,9 @@ @@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Godot;
namespace EGFramework{
public class EGUDP : IEGFramework, IModule, IProtocolSend, IProtocolReceived
{
@ -34,6 +33,7 @@ namespace EGFramework{ @@ -34,6 +33,7 @@ namespace EGFramework{
{
UdpClient udpDevice = new UdpClient(localPort);
UDPDevices.Add(localPort,udpDevice);
//udpDevice.EnableBroadcast = true;
HandleUDPListenAsync(udpDevice);
//StartListening(localPort);
}
@ -54,6 +54,7 @@ namespace EGFramework{ @@ -54,6 +54,7 @@ namespace EGFramework{
{
try
{
//GD.Print("UDP listened in "+((IPEndPoint)client.Client.LocalEndPoint).Port);
while (true)
{
UdpReceiveResult data = await client.ReceiveAsync();
@ -63,21 +64,30 @@ namespace EGFramework{ @@ -63,21 +64,30 @@ namespace EGFramework{
ResponseMsgs.Enqueue(receivedMsgs);
}
}
catch (Exception)
catch (Exception e)
{
GD.Print("Listen false by:"+e);
}
}
public void SendByteData(string host,int port,byte[] data){
UdpClient udpClient = new UdpClient();
UdpClient udpClient;
if(UDPDevices.Count>0){
udpClient = UDPDevices.First().Value;
}else{
udpClient = new UdpClient();
}
try{
GD.Print(udpClient.EnableBroadcast);
udpClient.Send(data, data.Length, host, port);
}
catch ( Exception e ){
Godot.GD.Print(e.ToString());
}
udpClient.Close();
udpClient.Dispose();
if(UDPDevices.Count<=0){
udpClient.Close();
udpClient.Dispose();
}
}
public void SendByteData(string destination,byte[] data){
SendByteData(destination.GetHostByIp(),destination.GetPortByIp(),data);
@ -118,6 +128,9 @@ namespace EGFramework{ @@ -118,6 +128,9 @@ namespace EGFramework{
public static void EGUDPListen(this IEGFramework self ,int port){
self.GetModule<EGUDP>().ListenUDP(port);
}
public static void EGUDPEndListen(this IEGFramework self ,int port){
self.GetModule<EGUDP>().EndListenUDP(port);
}
}
}

1
project.godot

@ -88,4 +88,5 @@ jump={ @@ -88,4 +88,5 @@ jump={
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"

Loading…
Cancel
Save