Werkt nog niet

This commit is contained in:
Yorick Rommers
2015-10-15 14:36:51 +02:00
parent 78c86d5680
commit bdf6366dc0
5 changed files with 42 additions and 11 deletions
+10 -1
View File
@@ -28,9 +28,18 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Name = "Form1";
this.Text = "Form1"; this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
} }
#endregion #endregion
+6 -2
View File
@@ -16,8 +16,12 @@ namespace MusicPlayer
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
APIHandler api = new APIHandler(); // nw.SendString("GET / HTTP/1.1");
NetworkHandler nw = new NetworkHandler("83.128.250.123", api);
}
private void Form1_Load(object sender, EventArgs e)
{
} }
} }
@@ -58,6 +58,9 @@
<Compile Include="NetworkHandler.cs" /> <Compile Include="NetworkHandler.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+20 -8
View File
@@ -1,4 +1,5 @@
using System.Text; using System;
using System.Text;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
@@ -7,13 +8,16 @@ namespace MusicPlayer
class NetworkHandler class NetworkHandler
{ {
private int port = 8585; private int port = 8585;
private Socket s; private TcpClient s;
private NetworkStream serverStream;
private APIHandler api; private APIHandler api;
public NetworkHandler(string ip, APIHandler apihandler) public NetworkHandler(string ip, APIHandler apihandler)
{ {
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Console.WriteLine("Hello");
s = new TcpClient();
s.Connect(ip, port); s.Connect(ip, port);
serverStream = s.GetStream();
ThreadStart thread = new ThreadStart(ReceiveData); ThreadStart thread = new ThreadStart(ReceiveData);
Thread childThread = new Thread(thread); Thread childThread = new Thread(thread);
childThread.Start(); childThread.Start();
@@ -21,17 +25,25 @@ namespace MusicPlayer
} }
public void SendString(string m) public void SendString(string m)
{ {
byte[] req_as_bytes = Encoding.UTF8.GetBytes(m); byte[] b = Encoding.UTF8.GetBytes(m);
s.Send(req_as_bytes); serverStream.Write(b, 0, b.Length);
serverStream.Flush();
} }
public void ReceiveData() public void ReceiveData()
{ {
Console.WriteLine("Hello2");
while (s.Connected) while (s.Connected)
{ {
byte[] data = new byte[1024 * 200]; Console.WriteLine("Hello3");
s.Receive(data); byte[] data = new byte[512];
Console.WriteLine("Hang je hier?");
int bytesRec = serverStream.Read(data, 0, data.Length);
Console.WriteLine("ën hier? ");
Console.WriteLine("Echoed test = {0}",Encoding.ASCII.GetString(data, 0, bytesRec));
string message = Encoding.ASCII.GetString(data); string message = Encoding.ASCII.GetString(data);
System.Console.WriteLine(message); System.Console.WriteLine(message);
//Iets doen met api calls //Iets doen met api calls
+3
View File
@@ -14,6 +14,9 @@ namespace MusicPlayer
[STAThread] [STAThread]
static void Main() static void Main()
{ {
APIHandler api = new APIHandler();
NetworkHandler nw = new NetworkHandler("www.imegumii.nl", api);
nw.SendString("GET /getsongbyid?id=102 HTTP/1.1");
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.Run(new Form1());