Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Qualcomm annuncia la nuova generazione di SoC Snapdragon 8 Elite Gen 6
Qualcomm annuncia la nuova generazione di SoC Snapdragon 8 Elite Gen 6
In occasione del proprio Snapdragon Summit Qualcomm annuncia i due nuovi chip per dispositivi mobile di fascia alta che entreranno nel mercato nel corso del 2027: tanta potenza a disposizione per elaborazioni di intelligenza artificiale sempre più complesse
realme 16 Pro Harry Potter Edition: il nuovo midrange ha uno stemma di Hogwarts che cambia colore al sole!
realme 16 Pro Harry Potter Edition: il nuovo midrange ha uno stemma di Hogwarts che cambia colore al sole!
Hogwarts arriva in fascia media grazie a realme, con una special edition che unisce la Quadra Light-Sensing Color-changing Tech, un baule in stile Hogwarts Express pieno di collezionabili e una scheda tecnica sostanzialmente identica al 16 Pro di partenza: ecco cosa cambia davvero, come si comporta nell'uso quotidiano e quanto vale in base al prezzo di 699,99 euro
Recensione REDMI Note 17 Pro: il midrange con batteria da 8.340 mAh e ricarica veloce
Recensione REDMI Note 17 Pro: il midrange con batteria da 8.340 mAh e ricarica veloce
REDMI Note 17 Pro porta in fascia media una batteria da 8.340 mAh con ricarica HyperCharge a 67W, un display AMOLED da 6,83 pollici capace di picchi di luminosità molto elevati e una struttura certificata TÜV SÜD contro cadute e infiltrazioni d'acqua, il tutto racchiuso in una scocca da 223 grammi. Lo abbiamo provato per diversi giorni tra fotocamera, prestazioni, autonomia e prezzo sul mercato italiano
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 07-11-2007, 09:17   #1
ally
Bannato
 
L'Avatar di ally
 
Iscritto dal: Jan 2003
Città:
Messaggi: 4423
...Java SocketServer...

...ciao...

...ho "rubato" un esempio di socket server da un noto programmatore italiano...ho adattato il codice alle mie esigenze e l'ho aggiunto ad un precedente programma in modo da poter monitorare tramite lan il funzionamento delle stesse...ho scelto come porta di comunicazione la 12000...la connessione verso il server avviene senza problemi ma le risposte che questo dovrebbe ritornare non vengono inoltrate...

Codice:
public class SocketServer {
	
	int port;
	BufferedReader socketIn = null;
	PrintWriter socketOut = null;
	ServerSocket socketServer = null;
	Socket sock = null;
	SocketAddress socketAddress = null;
	String line = ""; //$NON-NLS-1$
	static Logger AppLogger = Logger.getLogger("AppLogger"); //$NON-NLS-1$
	Player player;
	
	public SocketServer(){
		
		AppLogger.debug(""); //$NON-NLS-1$
	}
	
	public SocketServer(int port){
		
		System.out.println("server start on port : " + port); //$NON-NLS-1$
		
		this.port = port;
	}
	
	public void go(){
		
		new Thread(){
			public void run(){
				
				try{
					SocketServer.this.socketServer = new ServerSocket(SocketServer.this.port);
					SocketServer.this.sock = SocketServer.this.socketServer.accept();
					SocketServer.this.socketAddress = SocketServer.this.sock.getRemoteSocketAddress ();
					System.out.println ("Received connection from " + SocketServer.this.socketAddress); //$NON-NLS-1$
					try{
						SocketServer.this.socketIn = new BufferedReader (new InputStreamReader (SocketServer.this.sock.getInputStream ()));
						SocketServer.this.socketOut = new PrintWriter (SocketServer.this.sock.getOutputStream (), true);
						while ((SocketServer.this.line = SocketServer.this.socketIn.readLine ()) != null)
						{
							if (SocketServer.this.line.equals ("quit")) //$NON-NLS-1$
								break;
							request(SocketServer.this.line);
						}
					}
					finally
					{
						if (SocketServer.this.socketIn != null)
							SocketServer.this.socketIn.close ();
						if (SocketServer.this.socketOut != null)
							SocketServer.this.socketOut.close ();
						SocketServer.this.sock.close ();
					}
				}
				catch (Exception e)
				{
					AppLogger.debug(e.getMessage ());
				}
			}
			
		}.start();
		
	}
	
	public void setPlayer(Player player){
		
		this.player = player;
	}
	
	public void request(String request){
		
		if(request.equals("recent")) //$NON-NLS-1$
			this.socketOut.println(this.player.getRecentBarcode());
		else if(request.equals("cycle")) //$NON-NLS-1$
			this.socketOut.println("global cycle : "+this.player.isPlayer()+" audio cycle : "+this.player.isAudio()+" video cycle : "+this.player.isVideo()+" idle cycle : "+this.player.isIdle());  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
		else if(request.equals("timer")) //$NON-NLS-1$
			this.socketOut.println("idle counter : "+this.player.getCounter()/10+" of "+this.player.getGlobalVariables().getIdleInterval()/10+" restart counter : "+this.player.getRestartTime()*3+" of "+this.player.getGlobalVariables().getClientManagerRestart()*3); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
		else if(request.equals("error")) //$NON-NLS-1$
			this.socketOut.println("file error : "+this.player.getFileError()+" db error : "+this.player.getDbError()+" freezed screen : "+this.player.getFreezedScreen() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		else if(request.equals("mplayer")) //$NON-NLS-1$
			this.socketOut.println("mplayer running : "+Mplayer.getInstance().IsPlaying()+" playlist :  "+Mplayer.getInstance().getPlaylist());  //$NON-NLS-1$//$NON-NLS-2$
		else if(request.indexOf("execute")>-1) //$NON-NLS-1$
		{	
			this.player.serverRequest(request.substring(6,request.length()));
			this.socketOut.println(request+" sent"); //$NON-NLS-1$
		}
		this.socketOut.println(request);
		
	}
}
...qualche idea?...anche su chi sia questo noto programmatore italiano?...eh eh...

...ciao...
ally è offline   Rispondi citando il messaggio o parte di esso
Old 21-11-2007, 14:46   #2
ally
Bannato
 
L'Avatar di ally
 
Iscritto dal: Jan 2003
Città:
Messaggi: 4423
...ancora problemi con questo socket server...ho ripulito un po' il codice...il mio problema maggiore è di mantenere il server su dopo la disconnessione del client...al log out del client infatti il server termina...

Codice:
public class ServerEvo {
	
	int port = 12000;
	BufferedReader socketIn = null;
	PrintWriter socketOut = null;
	ServerSocket socketServer = null;
	Socket sock = null;
	SocketAddress socketAddress = null;
	String line = ""; //$NON-NLS-1$
	
	public ServerEvo(int port){
		
		System.out.println("server start on port : " + port); //$NON-NLS-1$
		try{
			this.port = port;
		    this.socketServer = new ServerSocket (this.port);
		    this.sock = this.socketServer.accept ();
		}catch(Exception e){
			System.out.println(e);
		}
		
		go();
	}
	
	public void go(){
		
		new Thread(){
			public void run(){
				try{
		            socketAddress = sock.getRemoteSocketAddress ();
		            System.out.println ("Received connection from " + socketAddress);
		            try{
		            	socketIn = new BufferedReader (new InputStreamReader (sock.getInputStream ()));
		            	socketOut = new PrintWriter (sock.getOutputStream (), true);
		                 while ((line = socketIn.readLine ()) != null)
		                {
		                    System.out.println ("Received from " + socketAddress + " string \"" + line + "\"");
		                    socketOut.println(line);
		                    if (line.equals ("quit"))
		                        break;
		                }
		            }
		            finally
		            {
		                System.out.println ("Disconnection from " + socketAddress);
		                if (socketIn != null)
		                    socketIn.close ();
		                if (socketOut != null)
		                    socketOut.close ();
		                sock.close ();
		            }
		        }
		        catch (Exception e)
		        {
		            System.out.println (e.getMessage ());
		        }
			}
			
		}.start();
		
	}
	
	public static void main(String args[]){
		
		new ServerEvo(12000);
		
	}
}
...il codice di Andbin da cui ho preso spunto è composto di due parti principali...il socketSrverRunnable che ho replicato nel metodo go annegando il thread...

Codice:
public class SocketServerRunnable implements Runnable{
	
    private Socket sock;

    public SocketServerRunnable (Socket sock){
    	
        this.sock = sock;
    }

    public void run(){
    	
        try{
            BufferedReader socketIn = null;
            PrintWriter socketOut = null;
            SocketAddress socketAddress = sock.getRemoteSocketAddress ();
            System.out.println ("Received connection from " + socketAddress);
            try{
            	socketIn = new BufferedReader (new InputStreamReader (sock.getInputStream ()));
            	socketOut = new PrintWriter (sock.getOutputStream (), true);
                String line;
                while ((line = socketIn.readLine ()) != null)
                {
                    System.out.println ("Received from " + socketAddress + " string \"" + line + "\"");
                    socketOut.println(line);
                    if (line.equals ("quit"))
                        break;
                }
            }
            finally
            {
                System.out.println ("Disconnection from " + socketAddress);
                if (socketIn != null)
                    socketIn.close ();
                if (socketOut != null)
                    socketOut.close ();
                sock.close ();
            }
        }
        catch (Exception e)
        {
            System.out.println (e.getMessage ());
        }
    }
}
...e il SocketServer...il ciclo while di quest'ultimo è responsabile di mantenere up il server anche dopo le disconessioni dei client...la mia idea era pero' di mantenere il server slegato dal resto del programma...dovrei quindi eliminare il ciclo while o isolarlo dal funzionamento del programma principale...

Codice:
public class SocketServer{
	
    private ServerSocket socketServer;

    public SocketServer(int port)throws IOException{
    	
        socketServer = new ServerSocket (port);
        start();
        
    }

    public void start() throws IOException {
    	
        Thread thread;
        SocketServerRunnable socketServerRunnable;

        System.out.println ("SocketSample1 Server started");

        try {
            while (true)
            {
                Socket socket = socketServer.accept ();
                socketServerRunnable = new SocketServerRunnable(socket);
                thread = new Thread (socketServerRunnable);
                thread.start ();
            }
        }
        finally
        {
            System.out.println ("SocketSample1 Server terminated");
            socketServer.close();
        }
    }
}
...grazie...ciao...
ally è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Qualcomm annuncia la nuova generazione di SoC Snapdragon 8 Elite Gen 6 Qualcomm annuncia la nuova generazione di SoC Sn...
realme 16 Pro Harry Potter Edition: il nuovo midrange ha uno stemma di Hogwarts che cambia colore al sole! realme 16 Pro Harry Potter Edition: il nuovo mid...
Recensione REDMI Note 17 Pro: il midrange con batteria da 8.340 mAh e ricarica veloce Recensione REDMI Note 17 Pro: il midrange con ba...
Insta360 Luna Ultra: la potenza del sensore da 1 pollice incontra la portabilità estrema Insta360 Luna Ultra: la potenza del sensore da 1...
Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa Marvel's Wolverine, la recensione: Logan torna p...
ASUS GPU Tweak III introduce lo spegnime...
Batterie per auto elettriche più ...
99,99€: imperdibile la soundbar LG S40T ...
Vivo X500 Series in arrivo anche in Euro...
Addio LiveNetTV: il raid della polizia m...
WhatsApp lavora a una nuova funzione per...
Un simil MacBook, ma con la RTX 5070: MS...
GAC Aion UT in anteprima, la piccola ele...
La Cina sfida Samsung e Micron: CXMT avv...
ECOVACS T50 OMNI Gen3 a 379€ non ha riva...
iPhone Duo, i video in 4K potrebbero sur...
Micron manda in pensione i chip GDDR7 da...
The Witcher 4: la scelta dell'Unreal Eng...
XBOX, il reset continua con nuovi licenz...
Apple AirTag torna a 26€, quello di seco...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 09:31.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v