Oppure

Loading
09/09/11 7:43
giosch
La prima parte di un mio progetto riguardate un server e dei client in chat via internet sfruttando synapse ha bisogno di ottenere l'ip locale del pc un una stringa es: xxx.xxx.xxx.xxx
questa mia procedura è abbastanza brutta e grezza, ma non sono riuscito usando i comandi interni della libreria, quindi mi appoggio al sito indirizzo-ip.com/…

program get_ip;
uses blcksock;
var
    sock: TTCPBlockSocket;
    str:string;
    num,num1:integer;
    ip:string;
function ipmacchina:string;
var
    buffer: String = '';
begin
    sock := TTCPBlockSocket.Create;

    sock.Connect('88.149.192.194', '80');
    // Was there an error?
    if sock.LastError <> 0 then
    begin
        writeLn('Could not connect to server.');
        halt(1);
    end;
    // Send a HTTP request
    sock.SendString('GET /ip.php?.txt/ HTTP/1.1'#13#10'Host: www.indirizzo-ip.com'#13#10#13#10);

    // Keep looping...
    repeat
        ipmacchina:=buffer;
        buffer := sock.RecvPacket(2000);
    // ...until there's no more data.
    until buffer = '';
end;


begin
    num1:=1;
    str:=ipmacchina;
    num:=length(str);
    num:=num-16;
    ip:=delete(str,num1,num);
    writeln(ip);
    readln;
end.    


il log della compilazione è

get_Ip.pas(38,9) Error: Incompatible types: got "untyped" expected "ShortString"
get_Ip.pas(42) Fatal: There were 1 errors compiling module, stopping


come posso risolvere? cosa ho sbagliato?
Ultima modifica effettuata da giosch 09/09/11 7:45
aaa
09/09/11 9:21
Il Totem
delete non restituisce nessun risultato. Modifica permanentemente il valore della stringa passata.
aaa
09/09/11 9:21
djleo
ciao giosch io ti consiglio di usare il c o meglio il c++
aaa
09/09/11 11:05
Goblin
Per conoscere l'IP della macchina basta sfruttare le uses WinSock,Windows, presenti anche nel dev-pascal, sotto un esempio

program GetMyIp;
Uses WinSock,Windows;
type
  TNetInfo=Record
             Localhost,
             LocalIP: String;
           End;
Procedure GetLocalNetworkInfo(Var NInfo: TNetInfo);
Var
   wVersionRequested: WORD;
   wsaData      : TWSAData;
   p            : PHostEnt;
   s            : Array[0..128] Of char;
Begin
   wVersionRequested := MAKEWORD(1, 1);
   WSAStartup(wVersionRequested, wsaData);
   GetHostName(@s, 128);
   p := GetHostByName(@s);
   NInfo.LocalHost := p^.h_Name;
   NInfo.LocalIP := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
   WSACleanup;
end;

Var oMyInfo:TNetInfo;
begin
  GetLocalNetworkInfo(oMyInfo);
  writeln(oMyInfo.LocalHost);
  writeln(oMyInfo.LocalIP);
  ReadLn;
end.


Ibis redibis non morieris in bello