diff --git a/MusicPlayer/MusicPlayer/Form1.Designer.cs b/MusicPlayer/MusicPlayer/Form1.Designer.cs new file mode 100644 index 0000000..397e6d1 --- /dev/null +++ b/MusicPlayer/MusicPlayer/Form1.Designer.cs @@ -0,0 +1,48 @@ +namespace MusicPlayer +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 261); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + + } + + #endregion + } +} + diff --git a/MusicPlayer/MusicPlayer/MainForm.cs b/MusicPlayer/MusicPlayer/MainForm.cs index 3bc9e55..5ccd68c 100644 --- a/MusicPlayer/MusicPlayer/MainForm.cs +++ b/MusicPlayer/MusicPlayer/MainForm.cs @@ -16,8 +16,12 @@ namespace MusicPlayer public MainForm() { InitializeComponent(); - APIHandler api = new APIHandler(); - NetworkHandler nw = new NetworkHandler("83.128.250.123", api); +// nw.SendString("GET / HTTP/1.1"); + + } + + private void Form1_Load(object sender, EventArgs e) + { } } diff --git a/MusicPlayer/MusicPlayer/MusicPlayer.csproj b/MusicPlayer/MusicPlayer/MusicPlayer.csproj index 359d999..553bd43 100644 --- a/MusicPlayer/MusicPlayer/MusicPlayer.csproj +++ b/MusicPlayer/MusicPlayer/MusicPlayer.csproj @@ -58,8 +58,8 @@ - - MainForm.cs + + Form1.cs ResXFileCodeGenerator diff --git a/MusicPlayer/MusicPlayer/NetworkHandler.cs b/MusicPlayer/MusicPlayer/NetworkHandler.cs index 2ac9dcf..9ea31a4 100644 --- a/MusicPlayer/MusicPlayer/NetworkHandler.cs +++ b/MusicPlayer/MusicPlayer/NetworkHandler.cs @@ -1,41 +1,44 @@ -using System.Text; +using System; +using System.Text; using System.Net.Sockets; using System.Threading; +using System.Net; +using System.IO; namespace MusicPlayer { class NetworkHandler { private int port = 8585; - private Socket s; + private string ip; private APIHandler api; public NetworkHandler(string ip, APIHandler apihandler) { - s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - s.Connect(ip, port); - ThreadStart thread = new ThreadStart(ReceiveData); - Thread childThread = new Thread(thread); - childThread.Start(); - api = apihandler; + this.ip = ip; + this.api = apihandler; } public void SendString(string m) { - byte[] req_as_bytes = Encoding.UTF8.GetBytes(m); - s.Send(req_as_bytes); - } - - public void ReceiveData() - { - while (s.Connected) + HttpWebRequest server = (HttpWebRequest)WebRequest.Create(ip+":"+port+"/"+m); + server.KeepAlive = false; + HttpWebResponse respond = (HttpWebResponse)server.GetResponse(); + Stream streamResponse = respond.GetResponseStream(); + StreamReader streamRead = new StreamReader(streamResponse); + Char[] readBuff = new Char[256]; + int count = streamRead.Read(readBuff, 0, 256); + string data = ""; + while (count > 0) { - byte[] data = new byte[1024 * 200]; - s.Receive(data); - string message = Encoding.ASCII.GetString(data); - System.Console.WriteLine(message); - //Iets doen met api calls + String outputData = new String(readBuff, 0, count); + data +=outputData; + count = streamRead.Read(readBuff, 0, 256); } + System.Console.WriteLine(data); + respond.Close(); + streamResponse.Close(); + streamRead.Close(); } } } diff --git a/MusicPlayer/MusicPlayer/Program.cs b/MusicPlayer/MusicPlayer/Program.cs index ec91107..e5e7fd4 100644 --- a/MusicPlayer/MusicPlayer/Program.cs +++ b/MusicPlayer/MusicPlayer/Program.cs @@ -14,6 +14,9 @@ namespace MusicPlayer [STAThread] static void Main() { + APIHandler api = new APIHandler(); + NetworkHandler nw = new NetworkHandler("http://www.imegumii.nl", api); + nw.SendString("getsongbyid?id=102"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm());