BNetEx

Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Gehe zu Seite Zurück  1, 2, 3 ... , 11, 12, 13  Weiter

Neue Antwort erstellen

 

Macintosh

BeitragMi, Apr 21, 2010 13:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Kann dein Modul leider nich kompilieren...
Fehler:
Code: [AUSKLAPPEN]
In file included from /Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:2:
/usr/include/net/if.h:264: error: field 'ifru_addr' has incomplete type
/usr/include/net/if.h:265: error: field 'ifru_dstaddr' has incomplete type
/usr/include/net/if.h:266: error: field 'ifru_broadaddr' has incomplete type
/usr/include/net/if.h:305: error: field 'ifra_addr' has incomplete type
/usr/include/net/if.h:306: error: field 'ifra_broadaddr' has incomplete type
/usr/include/net/if.h:307: error: field 'ifra_mask' has incomplete type
/usr/include/net/if.h:379: error: field 'addr' has incomplete type
/usr/include/net/if.h:380: error: field 'dstaddr' has incomplete type
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c: In function 'GetNetworkAdapter':
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:45: error: 'SIOCGIFHWADDR' undeclared (first use in this function)
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:45: error: (Each undeclared identifier is reported only once
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:45: error: for each function it appears in.)
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:46: error: 'struct ifreq' has no member named 'ifr_hwaddr'
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
/Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c:48: error: 'struct ifreq' has no member named 'ifr_netmask'
Build Error: failed to compile /Applications/BlitzMax/mod/vertex.mod/bnetex.mod/bsd.c

D2006

Administrator

BeitragMi, Apr 21, 2010 13:59
Antworten mit Zitat
Benutzer-Profile anzeigen
Das Problem wurde schon gelöst. Siehe hier.
Intel Core i5 2500 | 16 GB DDR3 RAM dualchannel | ATI Radeon HD6870 (1024 MB RAM) | Windows 7 Home Premium
Intel Core 2 Duo 2.4 GHz | 2 GB DDR3 RAM dualchannel | Nvidia GeForce 9400M (256 MB shared RAM) | Mac OS X Snow Leopard
Intel Pentium Dual-Core 2.4 GHz | 3 GB DDR2 RAM dualchannel | ATI Radeon HD3850 (1024 MB RAM) | Windows 7 Home Premium
Chaos Interactive :: GoBang :: BB-Poker :: ChaosBreaker :: Hexagon :: ChaosRacer 2

Progger93

BeitragMo, Mai 31, 2010 18:06
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey Leute ich bin jetzt gerade dabei zum 3. Mal mein Programm neu zu schreiben und Ich scheitere schon wieder an dem gleichen Problem..

Ich will ein simples Programm zum Datein versenden schreiben(Server + Client)
Der Client sendet zwar alle dateien zum Server, aber der Server liest aus irgend einem Grund nicht alles aus.
Hier mal die beiden Mainloops:
Client:BlitzMax: [AUSKLAPPEN]
Repeat

Local in:String
If KeyHit(KEY_C) Then in = "CONNECT"
If KeyHit(KEY_T) Then in = "TRANSFER"

If transfer Then 'Wenn eine Datei übertragen wird
If Not Eof(transferstream) Then
stream.WriteLine("PACKAGE") 'Dem server sagen, dass er im Anschluss ein Paket erhalten wird
Local buf:Byte[4096]
stream.WriteBytes(buf, transferstream.Read(buf, 4096)) '4KB der Datei in den Stream schreiben
While stream.SendMsg() Wend;
WriteStdout("Sending Package~n")
Else
stream.WriteLine("FINISH") 'Dem Server sagen, dass alle Pakete verschickt sind
While stream.SendMsg() Wend;
transfer = False
transferstream.Close()
WriteStdout("Finished Sending Package~n")
EndIf
End If

Select in.ToUpper()
Case "TRANSFER"
stream.WriteLine("TRANSFER") 'Dem Server sagen, dass ein Dateitransfer startet und ihm wichtige Daten schicken
Local file:String = "text.txt"
stream.WriteLine(file)
stream.WriteInt(FileSize(file))
While stream.SendMsg() Wend;
transfer = 1
transferstream = ReadFile(file)
Case "CONNECT"
stream = connect(ip)
Case "END" Or "EXIT"
End
End Select

Until KeyHit(KEY_ESCAPE) Or AppTerminate()

Server:BlitzMax: [AUSKLAPPEN]
Repeat
newstream = Server.Accept() 'Nach neuen Clienten suchen
If newstream Then

Local c:TClient = TClient.Create(newstream) 'Falls neuer Client da ist, neuen Clienten erstellen
ClientList.AddLast(c)
c.stream.GetLocalIP()
Print("<Connected> " + ..
"@IP:" + TNetwork.StringIP(newstream.GetLocalIP()) + ..
"@Port:" + newstream.GetLocalPort())
EndIf

For Local c:TClient = EachIn ClientList
If c.stream.RecvAvail() Then
While c.stream.RecvMsg() Wend; 'Nachrichten in den Streambuffer schreiben
If c.stream.Size() > 0 'Wenn was im Streambuffer ist
command = c.stream.ReadLine() 'Anforderung vom Clienten auslesen
Select command
Case "TRANSFER"
'Falls ein FileTransfer vom server begonnen wurde die Datei zum schreiben öffnen
Filestream = WriteFile(f.filename)
Case "PACKAGE"
Print "PACKAGE ERHALTEN"
Local buf:Byte[4096] '4KB an Daten in die Datei schreiben
Filestream.writebytes(buf, c.stream.Read(buf, 4096))
Case "FINISH"
Filestream.Close() 'Falls alle Pakete übertragen wurden den Stream schließen
Print "FINISHED"
End Select
EndIf
End If
Next
Until KeyHit(KEY_ESCAPE) Or AppTerminate()

Vermutlich liegt der Fehler daran, dass die Nachrichten falsch versendet/empfangen werden und somit nicht alles auf einmal ankommt.

Wäre echt nett wenn ihr mir helfen könntet.
MfG Pascal
Win 7|T7250@2.0Ghz|3GB RAM|M8600GT

D2006

Administrator

BeitragMo, Mai 31, 2010 19:39
Antworten mit Zitat
Benutzer-Profile anzeigen
Du solltest dich unbedingt entscheiden, ob du zeilenweise oder binär sendest. Ich denke, die Mischung wird deinem Programm das Genick brechen. Wenn das letzte Package einer Datei z.B. nur 1 KB groß ist und sofort eine neue anfängt, dann kriegt das der Server nie mit, weil er denkt, dass der Anfang der neuen Datei noch zu den 4 KB der alten gehört. Weiterhin sendest du zwar den Dateinamen, liest ihn aber nicht aus.

Meine Empfehlung: Strings nicht per Write/ReadLine sondern per Write/ReadString übertragen. Weiterhin für jedes Package erstmal die Bytelänge des Packages übertragen, damit der Server auch die korrekt Anzahl an Bytes ausliest.
Intel Core i5 2500 | 16 GB DDR3 RAM dualchannel | ATI Radeon HD6870 (1024 MB RAM) | Windows 7 Home Premium
Intel Core 2 Duo 2.4 GHz | 2 GB DDR3 RAM dualchannel | Nvidia GeForce 9400M (256 MB shared RAM) | Mac OS X Snow Leopard
Intel Pentium Dual-Core 2.4 GHz | 3 GB DDR2 RAM dualchannel | ATI Radeon HD3850 (1024 MB RAM) | Windows 7 Home Premium
Chaos Interactive :: GoBang :: BB-Poker :: ChaosBreaker :: Hexagon :: ChaosRacer 2
 

Lion

BeitragMo, Mai 31, 2010 20:08
Antworten mit Zitat
Benutzer-Profile anzeigen
https://www.blitzforum.de/foru...hp?t=34697
Dürfte das gleiche sein. Wie D2006 geschrieben hat oder ich in dem anderen Thread - Am Anfang einmal kurz die Dateigröße übertragen und dann beim Empfänger Repeat Until Dateigröße erreicht.
Intel Core 2 Quad 4x2.66 ghz - 4gb ddr2 - nvidia GeForce GTX660 2gb
Intel Atom 1x1.83 ghz - 2gb ddr2 - intel GMA 3150 256mb
AMD A10-5750M 4x2.5 ghz - 8 gb ddr4 - AMD R9 M290x

Progger93

BeitragMo, Mai 31, 2010 20:49
Antworten mit Zitat
Benutzer-Profile anzeigen
Hmm bei mir funktioniert es bisher jetzt, solange ich direkt die .exe starte. Starte ich hingegen das Programm mit BLIde/MaxIDE geht nichts Sad. Füge ich nun ein Delay ein, welches bei jedem Befehl der ankommt 700ms wartet, funktioniert es wieder überall...

Client:BlitzMax: [AUSKLAPPEN]
Repeat

Local in:String
If KeyHit(KEY_C) Then in = "CONNECT"
If KeyHit(KEY_T) Then in = "TRANSFER"

If transfer Then 'Wenn eine Datei übertragen wird
If Not transferstream.Eof() Then
stream.WriteByte(2) 'Dem server sagen, dass er im Anschluss ein Paket erhalten wird
Local buf:Byte[4096]
Local size:Int = transferstream.Size() - transferstream.Pos()
WriteStdout("Streamsize: " + size + "~n")
If size < 4096 Then
stream.WriteInt(size)
stream.WriteBytes(buf, transferstream.Read(buf, size)) '4KB der Datei in den Stream schreiben
Else
stream.WriteInt(4096)
stream.WriteBytes(buf, transferstream.Read(buf, 4096))
EndIf
While stream.SendMsg() Wend;
WriteStdout("Sending Package~n")
Else
stream.WriteByte(3) 'Dem Server sagen, dass alle Pakete verschickt sind
While stream.SendMsg() Wend;
transfer = False
transferstream.Close()
WriteStdout("Finished Sending Package~n")
EndIf
End If

Select in.ToUpper()
Case "TRANSFER"
stream.WriteByte(1) 'Dem Server sagen, dass ein Dateitransfer startet und ihm wichtige Daten schicken
Local file:String = "text.txt"
stream.WriteInt(file.Length)
stream.WriteString(file)
stream.WriteInt(FileSize(file))
While stream.SendMsg() Wend;
transfer = 1
transferstream = ReadFile(file)
Case "CONNECT"
stream = connect(ip)
Case "END" Or "EXIT"
End
End Select

Until KeyHit(KEY_ESCAPE) Or AppTerminate()


Server:BlitzMax: [AUSKLAPPEN]
For Local c:TClient = EachIn ClientList
If c.stream.RecvAvail() Then
c.stream.RecvMsg()

If c.stream.size() > 0
While Not c.stream.Eof()
Print "Streamgrösse: " + c.stream.size()

command = c.stream.ReadByte()

Print "Befehl: " + command

Select command
Case 1
Local f:Tfiletransfer = New Tfiletransfer
f.filename = c.stream.ReadString(c.stream.ReadInt())
f.size = c.stream.ReadInt()
Print "Name: " + f.filename
Print "Grösse: " + f.size
ListAddLast(FileTransferList, f)

Filestream = WriteFile(f.filename)

Case 2
Local size:Int = c.stream.ReadInt()
Local buf:Byte[size]
Filestream.writebytes(buf, c.stream.Read(buf, size))
Print "PACKAGE ERHALTEN [" + size + "]"

Case 3
Filestream.Close()
Print "FINISHED"
End Select

Wend
While Not c.stream.Eof()
WriteStdout(c.stream.ReadByte())
Wend

EndIf
End If
Next
MfG Pascal
Win 7|T7250@2.0Ghz|3GB RAM|M8600GT
 

Lion

BeitragMo, Jan 03, 2011 15:00
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey hey,
habe mal gerade eine eher die Logik betreffende Frage zu dem ganzen...
Code: [AUSKLAPPEN]

If UDPStream.RecvAvail() Then
   While UDPStream.RecvMsg() ; Wend
   While Not UDPStream.Eof()
      Local udpplayer:Tplayer = SearchClient(udpstream.ReadInt())'eher unwichtig für meine frage
      ReadUDPMessage(UDPStream.ReadByte(), udpplayer)' Wertet die nachricht aus
   Wend
EndIf


Diesen Abschnitt hab ich in der Hauptschleife stehen um eben UDP-Abfragen reinzubekommen, nun frage ich mich doch, was passiert, wenn zwei Leute gleichzeitig eine Anfrage an den Server schicken... Bzw wenn beides gleichzeitig von Recvmsg() aufgenommen wird. Denn das Problem wäre nicht, dass da irgendwie zwei Datenströme zusammenkommen, nur muss ich in ReadUDPMessage(...) ja gegebenenfalls auf den Client antworten, jedoch weiß der Server dann ja über udpstream.getmsgip() bzw udpstream.getmsgport() nur die IP und den Port von einem der clients und würde dann zwar beide Anfragen auswerten und auch Antworten schicken, da aber dieser get-kram nur vom letzten speichert würde ein Client zwei Antworten kriegen und der andere keine?
Oder sieht das in der Praxis anders aus und z.B. Client A blockiert für den Schleifenablauf dann ReceiveMSG() und Client B kommt dann im nächsten dran? Wobei das ja eventuell irgendwo ineffizient wäre... Gibt es einen Befehl, der Ip/port des senders von dem zuletzt abgearbeiteten Byte/int/wasauchimmer ausgibt?
Oder hab ich die Befehlsbeschreibung falsch verstanden...?
Gruß
Intel Core 2 Quad 4x2.66 ghz - 4gb ddr2 - nvidia GeForce GTX660 2gb
Intel Atom 1x1.83 ghz - 2gb ddr2 - intel GMA 3150 256mb
AMD A10-5750M 4x2.5 ghz - 8 gb ddr4 - AMD R9 M290x

Vertex

BeitragMo, Jul 11, 2011 21:10
Antworten mit Zitat
Benutzer-Profile anzeigen
Es gibt leider nichts Neues zu BNetEx. Ich habe auf meiner Festplatte noch ein paar Hilfsfunktionen gefunden, die bei der Netzwerk-Programmierung hilfreich sein könnten. Ehe sie dort verstauben, poste ich sie lieber hier. Das war ursprünglich mal für eine grundauf neue Version von BNetEx als Zusatzmodul gedacht Smile

Es bietet CRC16, CRC32, MD5, SHA1, SHA256, RC4. Bei der Huffman-Komprimierung kann ich mich noch daran erinnern, dass sie schonmal den Baum korrekt als Header kodieren konnte, aber den Inhalt selber nicht. Also hier Finger weg, ist nicht für den produktiven Einsatz. Den Rest habe ich immer in ein paar Tests mit PHP verglichen, glaube ich Smile
BlitzMax: [AUSKLAPPEN]
SuperStrict

Framework BRL.Blitz
Import BRL.Stream
Import BRL.Random

Rem
Local stream:TStream = WriteStream("C:\huffman.txt")
__COMMENT1__
Huffman.CompressString("MISSISSIPPI", stream)
stream.Close()
End Rem


Private

' circular rotate left
Function rol:Int(value:Int, shift:Int)
Return (value Shl shift) | (value Shr (32 - shift))
End Function

' circular rotate right
Function ror:Int(value:Int, shift:Int)
Return (value Shr shift) | (value Shl (32 - shift))
End Function

Function hexadecimal:String(value:Int)
Local buffer : Byte[8], ..
i : Int, ..
char : Byte

For i = 7 To 0 Step -1
char = (value & $0F)
If char > 9 Then
char :+ Asc("a") - 10
Else
char :+ Asc("0")
EndIf

buffer[i] = char
value :Shr 4
Next

Return String.FromBytes(buffer, 8)
End Function

Function binary:String(value:Int)
Local buffer : Byte[32], ..
i : Int

For i = 31 To 0 Step -1
buffer[i] = (value & %1) + Asc("0")
value :Shr 1
Next

Return String.FromBytes(buffer, 32)
End Function

Function rightString:String(value:String, count:Int)
Return value[(value.length - count)..(value.length)]
End Function

Public

Type CRC16
Const CCITT : Short = $8408, ..
IBM : Short = $A001

Global table : Short[256]

Function Init(polynomial:Short = IBM)
Local i : Int, ..
j : Int, ..
value : Short, ..
temp : Short

For i = 0 To 255
value = 0
temp = i
For j = 0 To 7
If ((value ~ temp) & $0001) <> 0 Then
value = (value Shr 1) ~ polynomial
Else
value :Shr 1
EndIf
temp :Shr 1
Next
table[i] = value
Next
End Function

Function FromString:Short(value:String)
Local crc : Short, ..
i : Int

crc = $FFFF
For i = 0 Until value.Length
crc = (crc Shr 8) ~ table[(crc ~ value[i]) & $FF]
Next

Return crc
End Function

Function FromBuffer:Short(buffer:Byte Ptr, length:Int)
Local crc : Short, ..
i : Int

If (Not buffer) Or length < 0 Then Throw("failed")

crc = $FFFF
While length > 0
crc = (crc Shr 8) ~ table[(crc ~ buffer[0]) & $FF]
buffer :+ 1
length :- 1
Wend

Return crc
End Function

Function FromStream:Short(stream:TStream)
Local crc : Short, ..
i : Int

If Not stream Then Throw("failed")

crc = $FFFF
While Not stream.Eof()
crc = (crc Shr 8) ~ table[(crc ~ stream.ReadByte()) & $FF]
Wend

Return crc
End Function
End Type

Type CRC32
Const IEEE8023 : Int = $04C11DB7, ..
CASTAGNOLI : Int = $1EDC6F41, ..
KOOPMAN : Int = $741B8CD7

Global table : Int[]

Function Init(polynomial:Int = IEEE8023)
Local i : Int, ..
j : Int

table = New Int[256]
For i = 0 To 255
table[i] = reflect(i, 8) Shl 24

For j = 0 To 7
If table[i] & $80000000 Then
table[i] = (table[i] Shl 1) ~ polynomial
Else
table[i] :Shl 1
EndIf
Next

table[i] = reflect(table[i], 32)
Next

Function reflect:Int(value:Int, count:Byte)
Local out : Int, ..
i : Int

For i = 1 To count + 1
If value & 1 Then out :| 1 Shl (count - i)
value :Shr 1
Next

Return out
End Function
End Function

Function FromString:Int(value:String)
Local crc : Int, ..
i : Int

crc = $FFFFFFFF
For i = 0 Until value.Length
crc = (crc Shr 8) ~ table[(crc & $FF) ~ value[i]]
Next

Return crc ~ $FFFFFFFF
End Function

Function FromBuffer:Int(buffer:Byte Ptr, length:Int)
Local crc : Int, ..
i : Int

If (Not buffer) Or length < 0 Then Throw("failed")

crc = $FFFFFFFF
While length > 0
crc = (crc Shr 8) ~ table[(crc & $FF) ~ buffer[0]]
buffer :+ 1
length :- 1
Wend

Return crc ~ $FFFFFFFF
End Function

Function FromStream:Int(stream:TStream)
Local crc : Int, ..
i : Int

If Not stream Then Throw("failed")

crc = $FFFFFFFF
While Not stream.Eof()
crc = (crc Shr 8) ~ table[(crc & $FF) ~ stream.ReadByte()]
Wend

Return crc ~ $FFFFFFFF
End Function
End Type

Type MD5
Const K0 : Int = $5A827999, ..
K1 : Int = $6ED9EBA1, ..
K2 : Int = $8F1BBCDC, ..
K3 : Int = $CA62C1D6

Global block : Byte[64]
Global h0 : Int, h1 : Int, h2 : Int, h3 : Int

Global k : Int[] = ..
[$D76AA478, $E8C7B756, $242070DB, $C1BDCEEE, $F57C0FAF, $4787C62A, ..
$A8304613, $FD469501, $698098D8, $8B44F7AF, $FFFF5BB1, $895CD7BE, ..
$6B901122, $FD987193, $A679438E, $49B40821, $F61E2562, $C040B340, ..
$265E5A51, $E9B6C7AA, $D62F105D, $02441453, $D8A1E681, $E7D3FBC8, ..
$21E1CDE6, $C33707D6, $F4D50D87, $455A14ED, $A9E3E905, $FCEFA3F8, ..
$676F02D9, $8D2A4C8A, $FFFA3942, $8771F681, $6D9D6122, $FDE5380C, ..
$A4BEEA44, $4BDECFA9, $F6BB4B60, $BEBFBC70, $289B7EC6, $EAA127FA, ..
$D4EF3085, $04881D05, $D9D4D039, $E6DB99E5, $1FA27CF8, $C4AC5665, ..
$F4292244, $432AFF97, $AB9423A7, $FC93A039, $655B59C3, $8F0CCC92, ..
$FFEFF47D, $85845DD1, $6FA87E4F, $FE2CE6E0, $A3014314, $4E0811A1, ..
$F7537E82, $BD3AF235, $2AD7D2BB, $EB86D391]

Global r : Int[] = ..
[7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, ..
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, ..
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, ..
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]

Function reset()
h0 = $67452301
h1 = $EFCDAB89
h2 = $98BADCFE
h3 = $10325476
End Function

Function FromString(value:String)
Local length : Int, ..
bitLength : Long, ..
i : Int, ..
index : Int

reset()

length = value.Length
bitLength = length*8

' divide data into 512 bit blocks
i = 0
index = 0
Repeat
block[index] = value[i]
i :+ 1
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf
Until i = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
(Long Ptr(Byte Ptr(block) + SizeOf(block) - 8))[0] = bitLength
transform()
End Function

Function FromBuffer(buffer:Byte Ptr, length:Int)
Local bitLength : Long, ..
i : Int, ..
index : Int

If (Not buffer) Or length < 0 Then Throw("failed")
reset()

bitLength = length Shl 3

' divide data into 512 bit blocks
i = 0
While length >= SizeOf(block)
MemCopy(block, buffer, SizeOf(block))
buffer :+ SizeOf(block)
length :- SizeOf(block)
transform()
Wend
If length > 0 Then MemCopy(block, buffer, length)
index = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
(Long Ptr(Byte Ptr(block) + SizeOf(block) - 8))[0] = bitLength
transform()
End Function

Function FromStream(stream:TStream)
Local length : Int, ..
bitLength : Long, ..
i : Int, ..
index : Int

If Not stream Then Throw("failed")
reset()

' divide data into 512 bit blocks
While Not stream.Eof()
length = stream.Read(block, SizeOf(block))
bitLength :+ length Shl 3
If length < SizeOf(block) Then Exit
transform()
Wend
If length = 64 Then
index = 0
Else
index = length
EndIf

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
(Long Ptr(Byte Ptr(block) + SizeOf(block) - 8))[0] = bitLength
transform()
End Function

Function ToStr:String()
Return hexadecimal(bigEndian(h0)) + ..
hexadecimal(bigEndian(h1)) + ..
hexadecimal(bigEndian(h2)) + ..
hexadecimal(bigEndian(h3))

Function bigEndian:Int(value:Int)
Return (value & $FF) Shl 24 ..
| (value Shr 8 & $FF) Shl 16 ..
| (value Shr 16 & $FF) Shl 8 ..
| (value Shr 24 & $FF)
End Function
End Function

Function transform()
Global t : Int, ..
w : Int[64], ..
temp : Int
Global f : Int
Global a : Int, b : Int, c : Int, d : Int

a = h0 ; b = h1 ; c = h2 ; d = h3

MemCopy(w, block, SizeOf(block))

For t = 0 To 15
temp = d
f = d ~ (b & (c ~ d))
d = c
c = b
b = rol((a + f + k[t] + w[t]), r[t]) + b
a = temp
Next

For t = 16 To 31
temp = d
f = c ~ (d & (b ~ c))
d = c
c = b
b = rol((a + f + k[t] + w[(((5*t) + 1) & 15)]), r[t]) + b
a = temp
Next

For t = 32 To 47
temp = d
f = b ~ c ~ d
d = c
c = b
b = rol((a + f + k[t] + w[(((3*t) + 5) & 15)]), r[t]) + b
a = temp
Next

For t = 48 To 63
temp = d
f = c ~ (b | ~d)
d = c
c = b
b = rol((a + f + k[t] + w[((7*t) & 15)]), r[t]) + b
a = temp
Next

h0 :+ a ; h1 :+ b ; h2 :+ c ; h3 :+ d
End Function
End Type

Type SHA1
Const K0 : Int = $5A827999, ..
K1 : Int = $6ED9EBA1, ..
K2 : Int = $8F1BBCDC, ..
K3 : Int = $CA62C1D6

Global block : Byte[64]
Global h0 : Int, h1 : Int, h2 : Int, h3 : Int, h4 : Int

Function reset()
h0 = $67452301
h1 = $EFCDAB89
h2 = $98BADCFE
h3 = $10325476
h4 = $C3D2E1F0
End Function

Function FromString(value:String)
Local length : Int, ..
bitLength : Long, ..
i : Int, ..
index : Int

reset()

length = value.Length
bitLength = length*8

' divide data into 512 bit blocks
i = 0
index = 0
Repeat
block[index] = value[i]
i :+ 1
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf
Until i = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
block[56] = bitLength Shr 56
block[57] = bitLength Shr 48
block[58] = bitLength Shr 40
block[59] = bitLength Shr 32
block[60] = bitlength Shr 24
block[61] = bitlength Shr 16
block[62] = bitlength Shr 8
block[63] = bitlength
transform()
End Function

Function FromBuffer(buffer:Byte Ptr, length:Int)
Local bitLength : Long, ..
i : Int, ..
index : Int

If (Not buffer) Or length < 0 Then Throw("failed")
reset()

bitLength = length Shl 3

' divide data into 512 bit blocks
i = 0
While length >= SizeOf(block)
MemCopy(block, buffer, SizeOf(block))
buffer :+ SizeOf(block)
length :- SizeOf(block)
transform()
Wend
If length > 0 Then MemCopy(block, buffer, length)
index = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
block[56] = bitLength Shr 56
block[57] = bitLength Shr 48
block[58] = bitLength Shr 40
block[59] = bitLength Shr 32
block[60] = bitlength Shr 24
block[61] = bitlength Shr 16
block[62] = bitlength Shr 8
block[63] = bitlength
transform()
End Function

Function FromStream(stream:TStream)
Local length : Int, ..
bitLength : Long, ..
i : Int, ..
index : Int

If Not stream Then Throw("failed")
reset()

' divide data into 512 bit blocks
While Not stream.Eof()
length = stream.Read(block, SizeOf(block))
bitLength :+ length Shl 3
If length = SizeOf(block) Then transform()
Wend
index = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
block[56] = bitLength Shr 56
block[57] = bitLength Shr 48
block[58] = bitLength Shr 40
block[59] = bitLength Shr 32
block[60] = bitlength Shr 24
block[61] = bitlength Shr 16
block[62] = bitlength Shr 8
block[63] = bitlength
transform()
End Function

Function ToStr:String()
Return hexadecimal(h0) + hexadecimal(h1) + hexadecimal(h2) + hexadecimal(h3) + hexadecimal(h4)
End Function

Function transform()
Global t : Int, ..
temp : Int, ..
w : Int[80]
Global a : Int, b : Int, c : Int, d : Int, e : Int

' little- to big endian
For t = 0 To 15
temp = t Shl 2
w[t] = block[temp] Shl 24 ..
| block[temp + 1] Shl 16 ..
| block[temp + 2] Shl 8 ..
| block[temp + 3]
Next

For t = 16 To 79
w[t] = rol(w[t - 3] ~ w[t - 8] ~ w[t - 14] ~ w[t - 16], 1)
Next

a = h0 ; b = h1 ; c = h2 ; d = h3 ; e = h4

' Round 1
For t = 0 To 19
temp = rol(a, 5) + (d ~ (b & (c ~ d))) + e + K0 + w[t]
e = d
d = c
c = rol(b, 30)
b = a
a = temp
Next

' Round 2
For t = 20 To 39
temp = rol(a, 5) + (b ~ c ~ d) + e + K1 + w[t]
e = d
d = c
c = rol(b, 30)
b = a
a = temp
Next

' Round 3
For t = 40 To 59
temp = rol(a, 5) + ((b & c) | (d & (b | c))) + e + K2 + w[t]
e = d
d = c
c = rol(b, 30)
b = a
a = temp
Next

' Round 4
For t = 60 To 79
temp = rol(a, 5) + (b ~ c ~ d) + e + K3 + w[t]
e = d
d = c
c = rol(b, 30)
b = a
a = temp
Next

h0 :+ a ; h1 :+ b ; h2 :+ c ; h3 :+ d ; h4 :+ e
End Function
End Type

Type SHA256
Global block : Byte[64]
Global h0 : Int, h1 : Int, h2 : Int, h3 : Int, ..
h4 : Int, h5 : Int, h6 : Int, h7 : Int

Global k : Int[] = ..
[$428A2F98, $71374491, $B5C0FBCF, $E9B5DBA5, $3956C25B, $59F111F1, ..
$923F82A4, $AB1C5ED5, $D807AA98, $12835B01, $243185BE, $550C7DC3, ..
$72BE5D74, $80DEB1FE, $9BDC06A7, $C19BF174, $E49B69C1, $EFBE4786, ..
$0FC19DC6, $240CA1CC, $2DE92C6F, $4A7484AA, $5CB0A9DC, $76F988DA, ..
$983E5152, $A831C66D, $B00327C8, $BF597FC7, $C6E00BF3, $D5A79147, ..
$06CA6351, $14292967, $27B70A85, $2E1B2138, $4D2C6DFC, $53380D13, ..
$650A7354, $766A0ABB, $81C2C92E, $92722C85, $A2BFE8A1, $A81A664B, ..
$C24B8B70, $C76C51A3, $D192E819, $D6990624, $F40E3585, $106AA070, ..
$19A4C116, $1E376C08, $2748774C, $34B0BCB5, $391C0CB3, $4ED8AA4A, ..
$5B9CCA4F, $682E6FF3, $748F82EE, $78A5636F, $84C87814, $8CC70208, ..
$90BEFFFA, $A4506CEB, $BEF9A3F7, $C67178F2]

Function reset()
h0 = $6A09E667
h1 = $BB67AE85
h2 = $3C6EF372
h3 = $A54FF53A
h4 = $510E527F
h5 = $9B05688C
h6 = $1F83D9AB
h7 = $5BE0CD19
End Function

Function FromBuffer(buffer:Byte Ptr, length:Int)
Local bitLength : Long, ..
i : Int, ..
index : Int

If (Not buffer) Or length < 0 Then Throw("failed")
reset()

bitLength = length Shl 3

' divide data into 512 bit blocks
i = 0
While length >= SizeOf(block)
MemCopy(block, buffer, SizeOf(block))
buffer :+ SizeOf(block)
length :- SizeOf(block)
transform()
Wend
If length > 0 Then MemCopy(block, buffer, length)
index = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
block[56] = bitLength Shr 56
block[57] = bitLength Shr 48
block[58] = bitLength Shr 40
block[59] = bitLength Shr 32
block[60] = bitlength Shr 24
block[61] = bitlength Shr 16
block[62] = bitlength Shr 8
block[63] = bitlength
transform()
End Function

Function FromStream(stream:TStream)
Local length : Int, ..
bitLength : Long, ..
i : Int, ..
index : Int

If Not stream Then Throw("failed")
reset()

' divide data into 512 bit blocks
While Not stream.Eof()
length = stream.Read(block, SizeOf(block))
bitLength :+ length Shl 3
If length = SizeOf(block) Then transform()
Wend
index = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
block[56] = bitLength Shr 56
block[57] = bitLength Shr 48
block[58] = bitLength Shr 40
block[59] = bitLength Shr 32
block[60] = bitlength Shr 24
block[61] = bitlength Shr 16
block[62] = bitlength Shr 8
block[63] = bitlength
transform()
End Function

Function FromString(value:String)
Local length : Int, ..
bitLength : Long, ..
i : Int, ..
index : Int

reset()

length = value.Length
bitLength = length*8

' divide data into 512 bit blocks
i = 0
index = 0
Repeat
block[index] = value[i]
i :+ 1
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf
Until i = length

' append one
block[index] = $80
index :+ 1

If index = 64 Then
transform()
index = 0
EndIf

' fill with zeros
MemClear(Byte Ptr(block) + index, 56 - index)

' append length in bits at the end of block
block[56] = bitLength Shr 56
block[57] = bitLength Shr 48
block[58] = bitLength Shr 40
block[59] = bitLength Shr 32
block[60] = bitlength Shr 24
block[61] = bitlength Shr 16
block[62] = bitlength Shr 8
block[63] = bitlength
transform()
End Function

Function ToStr:String()
Return hexadecimal(h0) + hexadecimal(h1) + hexadecimal(h2) + hexadecimal(h3) + ..
hexadecimal(h4) + hexadecimal(h5) + hexadecimal(h6) + hexadecimal(h7)
End Function

Function transform()
Global i : Int, ..
t0 : Int, ..
t1 : Int, ..
temp : Int, ..
w : Int[64]
Global a : Int, b : Int, c : Int, d : Int, e : Int, f : Int, g : Int, h : Int

' little- to big endian
For i = 0 To 15
temp = i Shl 2
w[i] = block[temp] Shl 24 ..
| block[temp + 1] Shl 16 ..
| block[temp + 2] Shl 8 ..
| block[temp + 3]
Next

For i = 16 To 63
w[i] = w[i - 16] + (ror(w[i - 15], 7) ~ ror(w[i - 15], 18) ~ (w[i - 15] Shr 3))..
+ w[i - 7] + (ror(w[i - 2], 17) ~ rOr(w[i - 2], 19) ~ (w[i - 2] Shr 10))
Next

a = h0 ; b = h1 ; c = h2 ; d = h3
e = h4 ; f = h5 ; g = h6 ; h = h7

For i=0 To 63
t0 = (ror(a, 2) ~ ror(a, 13) ~ ror(a, 22)) + ((a & b) | (b & c) | (c & a))
t1 = h + (ror(e, 6) ~ ror(e, 11) ~ ror(e, 25)) + ((e & f) | (~e & g)) + k[i] + w[i]

h = g
g = f
f = e
e = d + t1
d = c
c = b
b = a
a = t0 + t1
Next

h0 :+ a ; h1 :+ b ; h2 :+ c ; h3 :+ d
h4 :+ e ; h5 :+ f ; h6 :+ g ; h7 :+ h
End Function
End Type

Type RC4
Global s : Byte[256], ..
k : Byte[256]

Function FromString:String(value:String, key:String)
Local i : Int, ..
j : Int, ..
temp : Int, ..
index : Int, ..
out : Byte[]

If key.Length = 0 Then Throw("failed")
prepareKey(key)

out = New Byte[value.length]

i = 0
j = 0
For index = 0 Until value.length
i = (i + 1) Mod 256
j = (j + s[i]) Mod 256

' Swap
temp = s[i]
s[i] = s[j]
s[j] = temp

out[index] = value[index] ~ s[(s[i] + s[j]) Mod 256]
Next

Return String.FromBytes(out, value.length)
End Function

Function FromStream(in:TStream, out:TStream, key:String)
Local i : Int, ..
j : Int, ..
temp : Int

If key.Length = 0 Then Throw("failed")
prepareKey(key)

i = 0
j = 0
While Not in.Eof()
i = (i + 1) Mod 256
j = (j + s[i]) Mod 256

' Swap
temp = s[i]
s[i] = s[j]
s[j] = temp

out.WriteByte(in.ReadByte() ~ s[(s[i] + s[j]) Mod 256])
Wend
End Function

Function FromBuffer(in:Byte Ptr, out:Byte Ptr, length:Int, key:String)
Local i : Int, ..
j : Int, ..
temp : Int

If key.Length = 0 Then Throw("failed")
prepareKey(key)

i = 0
j = 0
While length > 0
i = (i + 1) Mod 256
j = (j + s[i]) Mod 256

' Swap
temp = s[i]
s[i] = s[j]
s[j] = temp

out[0] = in[0] ~ s[(s[i] + s[j]) Mod 256]
in :+ 1
out :+ 1

length :- 1
Wend
End Function

Function prepareKey(key : String)
Local i : Int, ..
j : Int, ..
temp : Int

For i = 0 To 255
s[i] = i
k[i] = key[i Mod key.length]
Next

' Swap
j = 0
For i = 0 To 255
j = (j + s[i] + k[i]) Mod 256
temp = s[i]
s[i] = s[j]
s[j] = temp
Next
End Function
End Type

Type THuffmanNode
Field character : Byte
Field count : Int
Field leftChild : THuffmanNode
Field rightChild : THuffmanNode
End Type

Type THuffmanHeader
Field rootNode : THuffmanNode
Field bitValue : Int
Field bitPosition : Int
Field characters : Short[256]
Field charCount : Int
Field stream : TStream
Field buffer : Byte Ptr

Method writeToStream(rootNode:THuffmanNode, stream:TStream)
If rootNode = Null Then Throw("failed")
If stream = Null Then Throw("failed")

reset()
Self.rootNode = rootNode
Self.stream = stream
generate(rootNode)
finishBits()

For Local i:Int = 0 Until charCount
stream.WriteByte(characters[i])
Next
End Method

Method writeToBuffer(rootNode:THuffmanNode, buffer:Byte Ptr)
If rootNode = Null Then Throw("failed")
If buffer = Null Then Throw("failed")

reset()
Self.buffer = buffer
generate(rootNode)
finishBits()

For Local i:Int = 0 Until charCount
buffer[0] = characters[i]
buffer :+ 1
Next
End Method

Method writeToString:String(rootNode:THuffmanNode)
Local startOffset : Byte Ptr, ..
header : String

If rootNode = Null Then Throw("failed")

reset()
buffer = MemAlloc(1024)
startOffset = buffer
generate(rootNode)
finishBits()

For Local i:Int = 0 Until charCount
buffer[0] = characters[i]
buffer :+ 1
Next

header = String.FromBytes(startOffset, buffer - startOffset)

MemFree(buffer)
buffer = Null

Return header
End Method

Method reset()
rootNode = Null
bitValue = 0
bitPosition = 0
charCount = 0
stream = Null
If buffer <> Null Then
MemFree(buffer)
buffer = Null
EndIf
End Method

Method generate(node:THuffmanNode)
If node.leftChild.leftChild <> Null Then
writeBit(False)
generate(node.leftChild)
Else
writeBit(True)
characters[charCount] = node.leftChild.character
charCount :+ 1
EndIf

If node.rightChild.leftChild <> Null Then
writeBit(False)
generate(node.rightChild)
Else
writeBit(True)
characters[charCount] = node.rightChild.character
charCount :+ 1
EndIf
End Method

Method writeBit(set:Int)
bitValue :Shl 1
bitPosition :+ 1
If set Then bitValue :| %1

?Debug
If set Then
DebugLog "1"
Else
DebugLog "0"
EndIf
?

If bitPosition > 7 Then
If stream <> Null Then
stream.WriteByte(bitValue)
ElseIf buffer <> Null Then
buffer[0] = bitValue
buffer :+ 1
EndIf
bitValue = 0
bitPosition :- 8
EndIf
End Method

Method finishBits()
If bitPosition > 0 Then
bitPosition = 8 - bitPosition
While bitPosition > 0
bitValue :Shl 1
bitPosition :- 1
Wend

If stream <> Null Then
stream.WriteByte(bitValue)
ElseIf buffer <> Null Then
buffer[0] = bitValue
buffer :+ 1
EndIf
EndIf
End Method
End Type

Type Huffman
Global list : THuffmanNode[256]
Global alphabet : Int[256, 2]
Global bitPosition : Int
Global bitValue : Int

Function CompressString(value:String, out:TStream)
Local character : Byte, ..
i : Int, ..
j : Int, ..
count : Int, ..
node : THuffmanNode, ..
found : Int

' List all existing characters with frequency
init()
count = 0
For i = 0 Until value.length
character = value[i]

found = False
j = 0
While list[j] <> Null
If list[j].character = character Then
node = list[j]
node.count :+ 1
found = True
Exit
EndIf
j :+ 1
Wend

If Not found Then
node = New THuffmanNode
node.character = character
node.count = 1
list[j] = node
count :+ 1
EndIf
Next

' Sorting list according to the frequency of characters
quickSort(0, count - 1)

' build binary tree
buildTree(count)

' build fast access alphabet
buildAlphabet(list[0], 0, 0)

Local h:THuffmanHeader = New THuffmanHeader
Local s:String = h.writeToString(list[0])
For Local i:Int = 0 Until s.length
DebugLog " > " + rightString(binary(s[i]), 8)
Next
DebugLog " > " + s

debugNode(list[0], "")
DebugLog ""
For i = 0 To 255
If alphabet[i, 1] > 0 Then
DebugLog "'" + Chr(i) + "': " + rightString(binary(alphabet[i, 0]), alphabet[i, 1])
EndIf
Next
End Function

Function init()
' Clear list
For Local i:Int = 0 To 255
list[i] = Null
alphabet[i, 1] = 0
Next
End Function

' Descend sorting
Function quickSort(low:Int, high:Int)
Local pivotNode : THuffmanNode, ..
tempNode : THuffmanNode, ..
i : Int, ..
j : Int

If low >= high Then Return
pivotNode = list[high]
i = low - 1
j = high + 1

While i <= j
Repeat
i :+ 1
Until i > j Or list[i].count <= pivotNode.count

Repeat
j :- 1
Until i > j Or list[j].count >= pivotNode.count

' Swap entries
If i < j Then
tempNode = list[i]
list[i] = list[j]
list[j] = tempNode
EndIf
Wend

quickSort(low, j) ' left part
quickSort(i, high) ' right part
End Function

Function buildTree(count:Int)
Local parentNode : THuffmanNode, ..
i : Int, ..
j : Int

While count >= 2
' Summarize the last two nodes to one
parentNode = New THuffmanNode
parentNode.rightChild = list[count - 1]
parentNode.leftChild = list[count - 2]

' Delete these nodes
list[count - 1] = Null
list[count - 2] = Null
count :- 2

parentNode.count = parentNode.leftChild.count ..
+ parentNode.rightChild.count

' Insert new parent node sorted in list
If count = 0 Then
' Only two entries exist
list[0] = parentNode
count = 1
ElseIf list[count - 1].count >= parentNode.count Then
' Insert at last
list[count] = parentNode
count :+ 1
ElseIf list[0].count <= parentNode.count Then
' Insert at first
For i = count To 1 Step -1
list[i] = list[i - 1]
Next
list[0] = parentNode
count :+ 1
Else
' Insert between two nodes
For i = 1 To count - 1
If list[i - 1].count >= parentNode.count ..
And list[i].count <= parentNode.count Then

For j = count To i + 1 Step - 1
list[j] = list[j - 1]
Next

list[i] = parentNode
count :+ 1

Exit
EndIf
Next
EndIf
Wend
End Function

Function buildAlphabet(node:THuffmanNode, path:Byte, count:Byte)
If node.leftChild <> Null Then
buildAlphabet(node.leftChild, path Shl 1, count + 1)
buildAlphabet(node.rightChild, path Shl 1 | %1, count + 1)
Else
alphabet[node.character, 0] = path
alphabet[node.character, 1] = count
EndIf
End Function

Function debugNode(node:THuffmanNode, space:String)
If node.character <> 0 Then
DebugLog space + node.count + "'" + Chr(node.character) + "'"
Else
DebugLog space + node.count
EndIf
If node.leftChild Then debugNode(node.leftChild, space + " ")
If node.rightChild Then debugNode(node.rightChild, space + " ")
End Function
End Type

Rem
Type TBitStream
Field stream : TStream
Field bitPosition : Int
Field bitBuffer : Int

Method Init(stream:TStream)
If stream = Null Then Throw("failed")

Self.stream = stream
bitPosition = 0
bitBuffer = 0
End Method

Method WriteBits(bits:Int, count:Int)
If
End Method

Method Finish()
End Method
End Type
End Rem


Ciao Olli
vertex.dreamfall.at | GitHub

ToeB

BeitragMo, Nov 14, 2011 16:04
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi !

Ich hab mal ne Frage. Ich wollte über die BNetEx in BlitzMax mit einem Programm in Blitz3D über UDP kommunizieren (Das es geht hab ich schon an simplen Sende / Empfangen Codes getestet). Jetzt möchte ich allerdings das ganze mit meiner SimpleUDP3.0 verbinden, und diese sendet die Daten nicht nur einmal sondern solange bis die Nachricht angekommen ist.

Jetzt zu meiner Frage: Kann ich mit dem TUDPStream auch Nachrichten an mehrerer Clients senden? Ich dachte mir das so, das ich vor jeder Nachricht die Remote-IP neu zuweise und dann Absende..

Denn: Wenn ich mit Blitz eine Nachricht sende kommt immer eine Leere Nachricht mit der IP 0.0.0.0:0 an, liegt es daran das ich immer neue RemoteIP's zuweise ?

Edit: Sry hatte vergessen RecvMsg auszuführen Embarassed Ich nehm alles Zurück! (Danke trotzdem fürs lesen!)

lg ToeB
Religiöse Kriege sind Streitigkeiten erwachsener Männer darum, wer den besten imaginären Freund hat.
Race-Project - Das Rennspiel der etwas anderen Art
SimpleUDP3.0 - Neuste Version der Netzwerk-Bibliothek
Vielen Dank an dieser Stelle nochmal an Pummelie, welcher mir einen Teil seines VServers für das Betreiben meines Masterservers zur verfügung stellt!

juse4pro

BeitragMi, Jan 25, 2012 23:05
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich bin hier grade am Verzweifeln... Auf der einen Seite muss man sich ums Puffern kümmern (nicht mehr als 1500 Bytes in ein TCP-Paket schreiben), auf der anderen Seite doch nicht (Server sendet mehrere Pakete [damit man 1500 Bytes nicht überschreitet] -> Trotzdem kommen bei Client mehrere Pakete zu einem zusammengeschnürrt an, und damit kann ich sie nicht mehr ordentlich zählen, weil mir ja keine Funktion sagt, was passiert ist)?

Also die Frage: Was meinst du mit "Puffern"?
 

Lion

BeitragMi, Jan 25, 2012 23:44
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich weiß ja nicht, was du genau vorhast, aber du kannst die Pakete problemlos mitzählen.
Ich vermute, dass du ein ganz simples
While Client.RecvMsg() ; Wend
verwendest. Wie du siehst, ist das eine While schleife, sprich wenn du einfach nur
Client.RecvMsg()
ausführst, dann erhälst du genau ein Paket. Zum loggen kannst du natürlich dann auch die Schleife behalten...
BlitzMax: [AUSKLAPPEN]
Local x%=1
While Client.RecvMsg()
Print "Paket Nummer: "+x
x:+1
Wend

Und dann dementsprechend Aktionen vornehmen.
Was du auch machen kannst, falls du z.B. Dateien überträgst (dann solltest du es vorallem machen!) ist, die Dateigröße vorher in einem Int zu schicken. Dann weiß der Verbindungspartner nämlich genau, wann Schluss ist.
Intel Core 2 Quad 4x2.66 ghz - 4gb ddr2 - nvidia GeForce GTX660 2gb
Intel Atom 1x1.83 ghz - 2gb ddr2 - intel GMA 3150 256mb
AMD A10-5750M 4x2.5 ghz - 8 gb ddr4 - AMD R9 M290x

juse4pro

BeitragDo, Jan 26, 2012 0:16
Antworten mit Zitat
Benutzer-Profile anzeigen
Genau das geht nicht, weil ich, wenn ich serverside 2 Pakete sende, manchmal beim Client ein ankommt, wo eben der Inhalt von beiden drinsteht... :/
Und ja: ich brauche es zum simplen downloaden einer Datei

Tankbuster

BeitragDo, Jan 26, 2012 0:57
Antworten mit Zitat
Benutzer-Profile anzeigen
Vielleicht liegt es ja daran, dass das erste Paket sich noch im Speicher befindet, ohne ausgelesen worden zu sein, und das zweite deshalb einfach darüber "gestapelt" wird

Wenn du jetzt ausließt, bis der Stream leer ist (also eventuell mehrere Pakete), ließt du natürlich alle Sachen aus, die im Stream sind, wenn du die Zählervariable danach dann erst erhöhst, bekommst du falsche Ergebnisse. Wink

Ich denke mal, daran liegts.
Sendest du was ab, dann wird es auch gesendet, und nicht irgendwie autovervollständigt.
Twitter
Download Jewel Snake!
Windows|Android

juse4pro

BeitragDo, Jan 26, 2012 1:01
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich bin mir eigentlich zu 100% sicher, dass ich exakt 1024+4 (1028) Bytes pro Paket versende... nur manchmal sind eben 2056 Bytes im Stream, jedenfalls nach den Info's die RecvAvail ausspuckt (+RecvMsg).

Dass der Server schneller sendet, als der Client empfängt, ist auch klar, doch sollte doch pro RecvMsg-Aufruf nur ein Paket geladen werden, und nicht 2, die zusammenkleben.

Tankbuster

BeitragDo, Jan 26, 2012 1:24
Antworten mit Zitat
Benutzer-Profile anzeigen
RecvMsg zeigt dir nur an, ob Nachrichten empfangen wurden, und liefert die IP zurück.
RecvAvail liefert dir die größe der Daten im Stream!

Nachdem die Pakete einzeln über TCP versendet wurden, werden sie halt in den Stream gesteckt. Wenn du die Größe des Streams also ausließt, ließt du nicht die Daten von einem TCP-Paket, sondern von allen TCP-Paketen, die im Stream darauf warten, gelesen zu werden.


Zitat:
Dass der Server schneller sendet, als der Client empfängt, ist auch klar, doch sollte doch pro RecvMsg-Aufruf nur ein Paket geladen werden, und nicht 2, die zusammenkleben.


Wenn der Server schneller sendet, als der Client bearbeitet, führt das unweigerlich zu Datenstau vom feinsten.

Und RecvMsg lädt garnichts, sondern liefert dir nur einen Wert Wink
Twitter
Download Jewel Snake!
Windows|Android

juse4pro

BeitragDo, Jan 26, 2012 1:37
Antworten mit Zitat
Benutzer-Profile anzeigen
Okay, und wie kann ich bezwecken, dass ich nur ein Paket in die Hand kriege? Wenn nicht würde ich mir nen nervigen Work-Around schreiben...

Nachrichtenstau? Ein bisschen Erfahrung hab ich ja schon, in Sachen Netzwerk. Wink Es werden immer nur 30 Pakete gesendet (Dabei ist der Server nunmal schneller, als der Client liest), danach wird auf den Client gewartet, der sich erst wieder die neuen 30 Pakete anfragen muss.

BtbN

BeitragDo, Jan 26, 2012 1:38
Antworten mit Zitat
Benutzer-Profile anzeigen
Wenn du nicht per Protokoll definiert hast, wie viele Daten es zu lesen gibt, machst du irgendwas komisch. Mir fällt auf jedenfall nicht ein, was man machen könnte, wo man nicht weiß, wie viel man Lesen muss, um ein Paket zu bekommen.

juse4pro

BeitragDo, Jan 26, 2012 1:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Doch, weis ich ja... Ist nur sehr sehr viel nerviger zu handeln... Vlt. hab ich auch einfach nen Denkfehler / Denkblockade im Hirn... (zu lange wach + EnergyDrinks [Relentless ist super! Very Happy])

Ich werde es anders machen... (vor den 30 Paketen, ein Integer, wo die Gesamtbyte-Zahl drinsteht, dann lese ich den ganzen Müll aus... Wink )

Tankbuster

BeitragDo, Jan 26, 2012 1:49
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich mache das immer so, dass ich am Anfang der Nachricht ein Byte/whatever habe, das festlegt, wie mit der Nachricht weiter umgegangen werden soll. Ist wohl die flexibelste und leichteste Lösung.

zum Beispiel für die Anmeldung am Server Byte 1, für irgendwas anderes Byte 2, und für ausloggen Byte 3, ect, ect.

Beim auslesen kannst du das dann so machen:

Pseudocode
Code: [AUSKLAPPEN]
If ErstesByteDerNachricht=1 Then

    ReadString()
    ReadString()
    ReadByte()

ElseIf ErstesByteDerNachricht=2 Then

    ReadInt()
    ReadInt()
    ReadLine()

[...]

EndIf
Twitter
Download Jewel Snake!
Windows|Android

juse4pro

BeitragDo, Jan 26, 2012 22:12
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich weis, das mache ich auch so... nur genau an dieser Stelle nicht. Wenn der Client eine Datei requestet, sendet der Server 30 Pakete am Stück, wenn ein "seek"-Paket (erstes Byte = 4) vom Client kommt.

Gehe zu Seite Zurück  1, 2, 3 ... , 11, 12, 13  Weiter

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group