|
@@ -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);
|
|
|
|
|
- s.Send(req_as_bytes);
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ byte[] b = Encoding.UTF8.GetBytes(m);
|
|
|
|
|
+ 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];
|
|
|
|
|
- s.Receive(data);
|
|
|
|
|
|
|
+ Console.WriteLine("Hello3");
|
|
|
|
|
+ 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
|