46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Godot;
|
|
using Network.PacketHandling;
|
|
|
|
namespace Network {
|
|
public class Client : Peer {
|
|
|
|
private PacketPeerUDP PacketPeer;
|
|
|
|
private Connection ServerConn;
|
|
|
|
private PacketBuffer TempBuffer;
|
|
private float Timer = 0;
|
|
|
|
public Client(PacketPeerUDP packetPeer) : base(packetPeer) {
|
|
PacketPeer = packetPeer;
|
|
TempBuffer = NewPacketBuffer();
|
|
TempBuffer.Write(1);
|
|
}
|
|
|
|
public override void Initialize(string address, int port) {
|
|
GD.print("Start client.");
|
|
GD.print("Starting to send stuff to " + address + ":" + port);
|
|
ServerConn = new Connection(address, port);
|
|
ServerConn.Name = "Server";
|
|
StartListening(port, "*");
|
|
}
|
|
|
|
public override void Update(float delta) {
|
|
Timer += delta;
|
|
if (Timer < 1) { return; }
|
|
Timer = 0;
|
|
SendBuffer(TempBuffer, ServerConn);
|
|
}
|
|
|
|
public override void ReceivePacket(PacketBuffer packetBuffer, Connection connection) {
|
|
GD.print("Client received stuff from " + connection.Name + " at " + connection.Address + " : " + connection.Port + " :");
|
|
while (packetBuffer.HasNext) {
|
|
GD.print(packetBuffer.Read());
|
|
}
|
|
}
|
|
|
|
public override void Connected(Connection conn) {
|
|
GD.print("Connected to " + conn.Name + " at " + conn.Address + ":" + conn.Port);
|
|
}
|
|
}
|
|
} |