Merge api to dev

This commit is contained in:
yorickr
2015-10-29 19:33:56 +01:00
5 changed files with 82 additions and 24 deletions
+48
View File
@@ -0,0 +1,48 @@
namespace MusicPlayer
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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
}
}
+6 -2
View File
@@ -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)
{
}
}
+2 -2
View File
@@ -58,8 +58,8 @@
<Compile Include="NetworkHandler.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
+23 -20
View File
@@ -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();
}
}
}
+3
View File
@@ -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());