<commit_before>﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

public class ImportScript : MonoBehaviour {
	
	public InputField IFipadr;
	public InputField IFport;
	public InputField IFmsg; // message to send
	public Text rcvText; // recieved text
	
	UdpClient client;
	int port;
	string lastRcvd;
	
	void Start() {
	}
	
	void Update() {
	}
	
	string getIpadr() {
		return IFipadr.text;
	}
	int getPort() {
		int res = Convert.ToInt16 (IFport.text);
		if (res < 0) {
			res = 0;
		}
		return res;
	}
	
	void procComm() {
		port = getPort();
		string ipadr = getIpadr ();
		
		client = new UdpClient ();
		
		// send
		string sendstr = IFmsg.text + System.Environment.NewLine;
		byte[] data = ASCIIEncoding.ASCII.GetBytes (sendstr);
		client.Client.SendTimeout = 1000; // msec
		client.Client.Blocking = false;

		Debug.Log ("send");
		client.Send (data, data.Length, ipadr, port);
		
		// receive
		client.Client.ReceiveTimeout = 2000; // msec
		IPEndPoint remoteIP = new IPEndPoint(IPAddress.Any, 0);
		lastRcvd = "";

		Debug.Log ("recv");

		while (true) {
			try {
				data = client.Receive (ref remoteIP);
				if (data.Length == 0) {
					Debug.Log("no response");
					return;
				}
				string text = Encoding.ASCII.GetString (data);
				lastRcvd += text;

				if (text.Contains("EOT")) {
					break;
				}
			} catch (Exception err) {
			}
		}
		
		client.Close ();

		if (lastRcvd.Length > 0) {
			System.IO.File.WriteAllText("import.csv", lastRcvd);
		}

		Debug.Log ("fin");
	}
	
	public void onClick() {
		Debug.Log ("on click");
		procComm ();
	}
}<commit_msg>add error handling<commit_after>﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

public class ImportScript : MonoBehaviour {
	
	public InputField IFipadr;
	public InputField IFport;
	public InputField IFmsg; // message to send
	public Text rcvText; // recieved text
	
	UdpClient client;
	int port;
	string lastRcvd;
	
	void Start() {
	}
	
	void Update() {
	}
	
	string getIpadr() {
		return IFipadr.text;
	}
	int getPort() {
		int res = Convert.ToInt16 (IFport.text);
		if (res < 0) {
			res = 0;
		}
		return res;
	}
	
	void procComm() {
		port = getPort();
		string ipadr = getIpadr ();
		
		client = new UdpClient ();
		
		// send
		string sendstr = IFmsg.text + System.Environment.NewLine;
		byte[] data = ASCIIEncoding.ASCII.GetBytes (sendstr);
		client.Client.SendTimeout = 1000; // msec
		client.Client.Blocking = false;

		Debug.Log ("send");
		try {
			client.Send (data, data.Length, ipadr, port);
		}
		catch (Exception e) {
			Debug.Log(e.Message);
			return;
		}

		// receive
		client.Client.ReceiveTimeout = 2000; // msec
		IPEndPoint remoteIP = new IPEndPoint(IPAddress.Any, 0);
		lastRcvd = "";

		Debug.Log ("recv");

		while (true) {
			try {
				data = client.Receive (ref remoteIP);
				if (data.Length == 0) {
					Debug.Log("no response");
					return;
				}
				string text = Encoding.ASCII.GetString (data);
				lastRcvd += text;

				if (text.Contains("EOT")) {
					break;
				}
			} catch (Exception err) {
				Debug.Log(err.Message);
				break;
			}
		}
		
		client.Close ();

		if (lastRcvd.Length > 0) {
			System.IO.File.WriteAllText("import.csv", lastRcvd);
		}

		Debug.Log ("fin");
	}
	
	public void onClick() {
		Debug.Log ("on click");
		procComm ();
	}
}
{'fraction_non_alphanumeric': 0.13736107153035051, 'fraction_numerical': 0.008549444286121402, 'mean_word_length': 2.9527027027027026, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7353305', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1225, 'n_words': 304}