<commit_before>using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Isis;

namespace DwarfServer
{
	public class DwarfServer
	{

		public DwarfServer ()
		{
		}

		static void Main(string[] args) {
			MemoryStream ms = new MemoryStream ();
			byte[] inbuffer = new byte[256];

			IPHostEntry iphost = Dns.GetHostEntry (Dns.GetHostName ());

			// Set the server to listen for connections on the Isis default port num + 2
			TcpListener server = new TcpListener (new IPEndPoint (iphost.AddressList [0], Isis.Isis.ISIS_DEFAULT_PORTNOp + 2));

			Console.WriteLine ("Starting Server on " + iphost.AddressList[0] + ":" + (Isis.Isis.ISIS_DEFAULT_PORTNOp + 2));
			server.Start ();

			//TODO: Write actual event loop for Server
			Console.WriteLine ("Waiting for client connection...");
			TcpClient client =  server.AcceptTcpClient ();

			NetworkStream stream = client.GetStream ();

			int len;

			byte[] header = new byte[4];
			stream.Read (header, 0, header.Length);
			Int32 msglen = System.BitConverter.ToInt32 (header, 0);

			inbuffer = new byte[msglen];
			stream.Read (inbuffer, 0, inbuffer.Length);
			string msg = System.Text.Encoding.Unicode.GetString(inbuffer);
			Console.WriteLine (msg);

		}
	}
}

<commit_msg>- Changed server implementation to something more sane/class-based<commit_after>using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Isis;

namespace DwarfServer
{
	public class DwarfServer
	{
		const int DEFAULT_PORT_NUM = 9845;

		private IPHostEntry iphost;
		private TcpListener tcp_server;
		private TcpClient tcp_client;
		private NetworkStream network_stream;

        public DwarfServer(int portnum = DEFAULT_PORT_NUM)
		{
			// Set this to our actual IP (according to DNS)
			this.iphost = Dns.GetHostEntry(Dns.GetHostName());

			// Set the server to listen for connections on the Isis default port num + 2
			this.tcp_server = new TcpListener(new IPEndPoint(iphost.AddressList[0], portnum));

			this.tcp_client = null;
			this.network_stream = null;
		}

		public void server_start()
		{
			Console.WriteLine("Starting Server on " + this.tcp_server.ToString());

			//TODO: What to do server is still active. No-op?
			this.tcp_server.Start();
		}

		public void wait_for_client(int timeout = 0)
		{
			if (timeout == 0 || this.tcp_server.Pending())
			{
				// Attempt to get the connection immediately if
				// 1) We don't care about timeouts (will block)
				// 2) We have a client already trying to connect
				this.tcp_client = this.tcp_server.AcceptTcpClient();
			} else { 
				throw new NotImplementedException();
			}
			
			this.network_stream = this.tcp_client.GetStream();
		}

		public string get_message()
		{
			byte[] inbuffer = new byte[256];

			byte[] header = new byte[4];
            this.network_stream.Read (header, 0, header.Length);
			Int32 msglen = System.BitConverter.ToInt32(header, 0);

			inbuffer = new byte[msglen];
			this.network_stream.Read(inbuffer, 0, inbuffer.Length);
			string msg = System.Text.Encoding.Unicode.GetString(inbuffer);
			return msg;
		}

		static void Main(string[] args)
		{
			DwarfServer dwarf_server = new DwarfServer();
			dwarf_server.server_start();

			Console.WriteLine ("Waiting for client connection...");
			dwarf_server.wait_for_client();
			
			while (true)
			{
				Console.WriteLine(dwarf_server.get_message());
				// dwarf_server.wait_for_client();
			}
		}
	}
}


{'fraction_non_alphanumeric': 0.11123919308357348, 'fraction_numerical': 0.010662824207492795, 'mean_word_length': 3.579155672823219, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4959536', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1101, 'n_words': 297}