public static String getFile(String deviceId, String fileFullPath) { int extLength = fileFullPath.Length - fileFullPath.LastIndexOf("."); String fileExt = fileFullPath.Substring(fileFullPath.LastIndexOf("."), extLength); JSONRequestIndex reqMsg = new JSONRequestIndex(deviceId, fileFullPath); JSONMessageWrapper msgWrapper = new JSONMessageWrapper("getFile", reqMsg.request()); try { String response = HttpClient.GET("getFile", msgWrapper.getMessage()); if (!string.IsNullOrEmpty(response)) { byte[] filebytes = Convert.FromBase64String(response); Guid gid = Guid.NewGuid(); FileStream fs = new FileStream(TEMP_LOCATION + gid + fileExt, FileMode.CreateNew, FileAccess.Write, FileShare.None); fs.Write(filebytes, 0, filebytes.Length); fs.Close(); return TEMP_LOCATION + gid.ToString() + fileExt; } return ""; } catch (WebException e) { //return Device Not Found return "DNF"; } }
/// <summary> /// Default constructor. /// </summary> public SurfaceWindow1() { InitializeComponent(); // Add handlers for window availability events AddWindowAvailabilityHandlers(); //Make the DirList ScatterView accessable globally GlobalDirList = this.DirList; //Or doing it in HTTP JSONMessageWrapper _msg = new JSONMessageWrapper("init", ""); //Test the connection to the server try { String response = HttpClient.GET("init", _msg.getMessage()); } catch (Exception e) { this.serverNotResondingDialog.Visibility = Visibility.Visible; } //TODO DELETE THIS. FOR TESTING ONLY //String deviceId = "87841656-3842-40cb-af59-389ee46b23cd"; //this.getIndexObject(deviceId); }
public static ArrayList getIndexObject(String deviceId, String dir) { JSONRequestIndex reqMsg = new JSONRequestIndex(deviceId, dir); JSONMessageWrapper msgWrapper = new JSONMessageWrapper("getIndex", reqMsg.request()); String response = HttpClient.GET("getIndex", msgWrapper.getMessage()); return Parser.parseIndexes(response); }
//Establish a connection to the server public void connect() { //Establish a connection, get the stream. this.clientSocket.Connect(this.ip, this.port); this.serverStream = clientSocket.GetStream(); //Prepare initiating JSON message to send JSONMessageWrapper _msg = new JSONMessageWrapper("init", ""); //Tell the server who I am this.write(_msg.getMessage()); //this.listen(); }
public static void StartClient() { // Connect to a remote device. try { // Establish the remote endpoint for the socket. IPAddress ipAddress = IPAddress.Parse(ip); IPEndPoint remoteEP = new IPEndPoint(ipAddress, port); // Create a TCP/IP socket. client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client); connectDone.WaitOne(); //Prepare JSON message to send JSONMessageWrapper _msg = new JSONMessageWrapper("init", ""); String message = _msg.getMessage(); // Send test data to the remote device. Send(message); sendDone.WaitOne(); // Receive the response from the remote device. Receive(); receiveDone.WaitOne(); // Write the response to the console. Console.WriteLine("Response received : {0}", response); } catch (Exception e) { Console.WriteLine(e.ToString()); } }