当我使用DataOutputStream时,在linux中断管

时间:2014-06-09 22:55:56

标签: linux windows pipe

Stackoverflow的良好平衡性

我正在尝试将流式传输到listen2myradio的Brodcasting Station,但是当我尝试在linux中执行此操作时,我发现了一个损坏的管道。

当我在Windows中使用此代码时,它可以很好地运行并且没有问题。

    import java.net.URL;
import java.net.URLConnection;
import java.net.Socket;
import java.io.DataOutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.BufferedOutputStream;
import java.io.OutputStreamWriter;
class Emisora{



    String LinkEspecial;
    String DireccionServidor;
    int PuertoServidor = 0;
    URL LinkDescarga;
    Socket sc;
    private void DefineLink(String URLS) throws Exception
    {
    this.LinkEspecial = URLS;
    System.out.println("Saliendo de DefineLink");
    }

    private void ObtenerInfoLink() throws Exception
    {
        if(this.LinkEspecial.isEmpty())
        {
        System.out.println("Primero debe usar el metodo 'DefineLink'");
        }
        else
        {
        URL link = new URL(this.LinkEspecial);
        this.LinkDescarga = link;
        System.out.println("Saliendo de ObtenerInfoLink");
        }

    }

    private void ConfigurarConexionServidor(String addres,int puerto)
    {
        this.DireccionServidor = addres;
        this.PuertoServidor = puerto;
        System.out.println("Saliendo de ConfigurarServidor");
    }

    private void ConexionServidor() throws Exception
    {
        if(this.DireccionServidor.isEmpty() || this.PuertoServidor == 0)

        {
            System.out.println("Por favor configure el servidor primero");
        }
        else
        {
            this.sc = new Socket(this.DireccionServidor,this.PuertoServidor);
            System.out.println("Saliendo de ConexionServidor");
        }
    }
    private void Streamings() throws Exception
    {
        URLConnection conexion = this.LinkDescarga.openConnection();
        BufferedInputStream lectura = new BufferedInputStream(conexion.getInputStream());
        ObjectOutputStream mensaje = new ObjectOutputStream(this.sc.getOutputStream());

        int constante = conexion.getContentLength();
        byte datos[] = new byte[1024];


        mensaje.writeBytes("password....\n");
        mensaje.writeBytes("icy-name:Radio\n");
        mensaje.writeBytes("icy-genre:Misc\n");
        mensaje.writeBytes("icy-url:http://www.shoutcast.com\n");
        mensaje.writeBytes("icy-irc:N/A\\\n");
        mensaje.writeBytes("icy-aim:N/A\\\n");
        mensaje.writeBytes("icy-pub:0\n");
        mensaje.writeBytes("icy-br:128\n");
        mensaje.writeBytes("content-type:audio/mpeg\n\n");



       int count = 0;
       while(count != constante)
       {
          int prueba = lectura.read();
          mensaje.writeByte(prueba);
          count++;

       } 


       this.sc.close();
       System.out.println("Saliendo de Streamings");
    }


         public static void main(String hola[]) throws Exception
    {
      Emisora control = new Emisora();
      control.DefineLink("https://www.dropbox.com/meta_dl/eyJzdWJfcGF0aCI6ICIiLCAidGVzdF9saW5rIjogZmFsc2UsICJzZXJ2ZXIiOiAiZGwuZHJvcGJveHVzZXJjb250ZW50LmNvbSIsICJpdGVtX2lkIjogbnVsbCwgImlzX2RpciI6IGZhbHNlLCAidGtleSI6ICJuM2wxZzZ4NzFwdWN0b2YifQ/AAOE6GutXJjrKx81FzH4Afzsf-N6Y9JtTdyRDErZ-dGNMQ?dl=1");
      control.ObtenerInfoLink();
      control.ConfigurarConexionServidor("82.145.47.187", 7846);
      control.ConexionServidor(); 
      control.Streamings();
    }

}

我不知道问题是什么。我已经尝试了更多的课程,但他们没有工作。

谢谢

PD:代码是西班牙语,但您可以更改它......它将是相同的。

0 个答案:

没有答案