Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 09.08.05 08:30 
Hallo !
Wie kann ich prüfen ob es sich bei einem TStream, den ich übergeben bekomme um einen StringStream handelt, also ob Text drin steht oder ob ein TJpeg in dem Stream drinsteckt ?

Danke !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Di 09.08.05 10:08 
Du liest die für eine JPEG Datei typischen Headerinformationen und liest, ob es sich um eine JPEG Datei handelt. Wenn nicht, als Text ausgeben (Das hindert aber nicht, falls ein BMP oder so drin ist. das muss jeweils einzeln geprüft werden). Als Beispiel kannst du dir (glaube ich) den Quelltext zu TImage.Graphic oder so ansehen, falls du ihn hast. Da wird ebenfalls so eine Prüfung gemacht (ich glaube da mal so etwas gesehen zu haben).

Gruß

_________________
Im Nachhinein ist man immer ein Schlauch!
"Dream as if you'll live forever, live as if you'll die today!" James Dean
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 10.08.05 08:10 
danke. das wäre ne möglichkeit. was andere als Text oder JPG wird nicht kommen, da ich den client der das schickt selber schreibe.
das konkrete Problem ist: ich verwende die SimpleTCP kompo aus der OpenSource Sparte und da bekommt man halt nur einen Input Stream im Input Event und ich muss schauen, was es ist.
aber ich werde mal deine Lösung mit anschauen !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mi 10.08.05 08:25 
Hallo!

Wenn du doch den Inhalt selber auch lieferst, schieb doch vorher noch ein Identifikationsmerkmal in den Stream.

Cu,
Udontknow
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 10.08.05 09:05 
wie geht das ?

_________________
In the beginning was the word.
And the word was content-type: text/plain.
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mi 10.08.05 09:23 
Das einfachste wäre wohl, vor den eigentlichen Daten einfach 1 Byte mit der Identifikation zu übertragen ( da haste ja schon 256 mögliche Datentypen abgedeckt ).


Dann liest du erst das eine Byte ein, weisst, was kommt und liest dann den Rest.

_________________
Bravery calls my name in the sound of the wind in the night...
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mi 10.08.05 10:36 
Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
const ID_JPG = 0;
const ID_TEXT = 1;

procedure JPGSenden(Filename:String);
var Stream:TMemoryStream;
var FileStream:TFileStream;
var ID:Integer;
begin
  Stream:=TMemoryStream.Create;
  try
    //Identifikationsmerkmal in Stream schreiben
    ID:=ID_JPG;
    Stream.WriteBuffer(ID,SizeOf(ID));

    //Daten des Bildes in Memorystream speisen
    FileStream:=TFileStream.Create(FileName, fmOpenRead);
    try
      Stream.CopyFrom(FileStream,FileStream.Size);
    finally
      FileStream.Free;
    end;

    //Senden
    Client.SendStream(Stream);
  finally
    Stream.Free;
  end;
end;


Cu,
Udontknow
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Mi 10.08.05 10:49 
Das ist dann wohl auch der klügste Weg:
Wenn Du beim Senden die Information über den Typ via Byte am Stream-Head mit übergeben hast, kannste Dir die clientside Type Prediction (Wahnsinnswort) sparen.

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 10.08.05 18:24 
danke für die vielen Tipps. Ich werds mal ausprobieren ! :D

_________________
In the beginning was the word.
And the word was content-type: text/plain.
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Do 11.08.05 07:27 
Ah, sorry dass ich jetzt erst antworte!
Wenn du den Client selbst schreibst ist es wirklich die beste Lösung, einfach eine FileID zu schicken, oder selber einen Header zu basteln!

Ich hatte gedacht, es kommen beliebige Daten an, von denen du nicht weißt, woraus sie bestehen könnten.

Gruß

_________________
Im Nachhinein ist man immer ein Schlauch!
"Dream as if you'll live forever, live as if you'll die today!" James Dean