server data rx changes

This commit is contained in:
Pin
2023-03-28 22:12:17 -04:00
parent 812096514d
commit 855c1a075f
5 changed files with 127 additions and 33 deletions

View File

@@ -2,16 +2,18 @@ package utils
import (
"encoding/binary"
"fmt"
"log"
"time"
//"fmt"
//"log"
"net"
"unicode/utf8"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/mdlayher/packet"
"saprusserver/structs"
//"saprusserver/structs"
)
type SocketCall struct {
@@ -21,8 +23,8 @@ type SocketCall struct {
func splitData(message string) []string {
data := []string{}
maxPacketLength := 8
//maxPacketLength := 1458
//maxPacketLength := 8
maxPacketLength := 1449
var i, j int
@@ -46,14 +48,26 @@ func (c* SocketCall)SendData(message string) {
iface, _ := net.InterfaceByName("virbr0")
c.Iface = iface
conn, _ := packet.Listen(iface, packet.Raw, int(layers.EthernetTypeIPv4), nil)
conn, err := packet.Listen(iface, packet.Raw, int(layers.EthernetTypeIPv4), nil)
c.conn = conn
if err != nil {
log.Panic(err)
}
splitMessage := splitData(message)
c.SendPackage(c.InitFileTransferPacket())
for i := 0; i < len(splitMessage); i++ {
c.SendPackage(c.FileTransferPacket(splitMessage[i]))
c.SendPackage(c.FileTransferPacket(splitMessage[i], uint16(i)))
time.Sleep(20 * time.Microsecond)
}
time.Sleep(200 * time.Microsecond)
c.SendPackage(c.EndFileTransferPacket())
return
}