Hi,
Habs jetzt so probiert:
Code:
[Serializable]
public struct TPlayerState
{
public UInt16 id;
public int x;
public int y;
public UInt32 color;
}
public static void RecClientData(object client)
{
Socket csock = client as Socket;
BinaryFormatter binf = new BinaryFormatter();
byte[] buff = new byte[14]; // Größere Pakete kommen zurzeit eh nicht an, von daher hab ichs mal so fest drin.
int len;
while ((len = csock.Receive(buff,SocketFlags.None)) > 0)
{
Stream ms = new MemoryStream();
ms.Write(buff,0,buff.Length);
ms.Position = 0;
switch (buff[0])
{
case 0: Console.WriteLine("...");
break;
case 1: TPlayerState ps = (TPlayerState)binf.Deserialize(ms); // <---- *)
Console.WriteLine(ps.y);
break;
default:break;
}
// ....
*) Ausnahme System.Runtime.Serialization.SerializationExceptio n wurde im ausgeführten Programm ausgelöst:
Das Streamende wurde erreicht, bevor die Verarbeitung abgeschlossen wurde.
Kann mir da jemand sagen was ich falsch mache? Versenden tu ich das ganze so:
Delphi-Quellcode:
type
TPlayerState = packed record
id: Word; // 1
x,y: Integer;
color: TColor;
end;
var data: TPlayerState;
begin
data.id := 1;
data.x := 20;
data.y := 40;
data.color := clred;
Client.Send(@data,SizeOf(TPlayerState));
end;
Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."