Ciao, ho provato a fare come mi hai detto te ma non va lo stesso, dando un occhiata al sito della Digital Mars sono riuscito a risolvere:
Client:
_________________________
import std.stdio; //Libreria standard
import std.socket; //Per usare i socket
void main(string[] args)
{
//Istanzio la classe TcpSocket
TcpSocket sock = new TcpSocket();
//new InternetAddress(indirizzo, porta)
sock.connect(new InternetAddress("IP", porta));
char[]str="Hello Socket!";
//Invio testo
sock.send(cast(ubyte[])str);//Lo converto in ubyte
sock.close();//Chiudo la socket
}
Server:
____________________________________
import std.stdio;
import std.socket;
void main(string[] args)
{
ubyte[] buffer=new ubyte[255];
TcpSocket sock = new TcpSocket();//Istanzio la classe TcpSocket
//E' possibile omettere l'indirizzo perchč
//c'č un costruttore che accetta solo la porta
//e come indirizzo prende quello del pc.
sock.bind(new InternetAddress(Porta));
sock.listen(1);
Socket serv=sock.accept();//Accetto la connessione in ingresso
serv.receiveFrom(buffer);//Ricevo i dati inviati e li immagazziono in un buffer
writefln(cast(string)buffer);//Li stampo a video
sock.close();//Chiudo i socket
serv.close();
}
Grazie e Ciao!!!
Ultima modifica effettuata da ^JAVA^ il 31/05/2008 alle 16:17 |