private void sendClipboardDatas() { //MessageBox.Show("Sending clipboard to server:" + i.ToString() + " .\nYou will be advised when the transfer is completed.", "Starting Transfer", MessageBoxButtons.OK, MessageBoxIcon.Information); Socket s = _host.ds(i); if (s == null) { EnableCB(); return; } IDataObject clipboardData = Clipboard.GetDataObject(); string[] formats = clipboardData.GetFormats(); try{ foreach (string format in formats) { //Console.WriteLine("Analizing clipboard. FORMAT FOUND: " + format); if (format == DataFormats.FileDrop) { continue; } MsgStream.Send(new DataMsgCBP(format, clipboardData.GetData(format)), _host.ds(i)); } /* SENDING FILE TYPE */ if (Clipboard.ContainsFileDropList()) { long size = ClipboardFiles.GetCBFilesSize(); if (size > ClipboardFiles.MaxSize) { if (MessageBox.Show("The size of clipboard's content is greater than MaxSize: " + ClipboardFiles.MaxSize + " \nConfirm the transfer?", "Closing Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { EnableCB(); return; } } MsgStream.Send(new InitFileCBP(), s); ClipboardFiles.SendClipboardFiles(s); MsgStream.Send(new StopFileCBP(), s); ConfirmCBP m = (ConfirmCBP)MsgStream.Receive(s); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Ops...\nSomething goes wrong during Clipboard Transfer[on Sending].\nThe connection will be closed.\nTry again later.", "Clipboard Transfer Error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); this.DisconnectionReq(); Console.WriteLine("Clipboard file transfer error: " + e.Message); } EnableCB(); return; }
private void Connect() { Socket tmpE = new Socket(SocketType.Stream, ProtocolType.Tcp); //event socket Socket tmpD = new Socket(SocketType.Stream, ProtocolType.Tcp); //clipboard socket object o = null; try { Console.WriteLine("Connecting EventSocket To -> " + IP + ":" + EP.ToString()); tmpE.Connect(IP, EP); /* Authentication on EventSocket*/ MsgStream.Send(new AuthMsg(PSW), tmpE); o = MsgStream.Receive(tmpE); if ((o is AckMsg) && (((AckMsg)o).ack)) { Console.WriteLine("Connection completed successful on EventSocket."); } else { throw new Exception(); } Console.WriteLine("Connecting DataSocket To -> " + IP + ":" + DP.ToString()); tmpD.Connect(IP, DP); /* Authentication on DataSocket */ Console.WriteLine("Starting authentication protocol."); MsgStream.Send(new AuthMsg(PSW), tmpD); o = MsgStream.Receive(tmpD); if ((o is AckMsg) && (((AckMsg)o).ack)) { Console.WriteLine("Connection completed successful on DataSocket."); } else { throw new Exception(); } _host.es(tmpE, i); _host.ds(tmpD, i); this.Connected(); } catch (Exception) { tmpE.Close(); tmpD.Close(); this.Disconnected(); } }
public override void Update() { base.Update(); if (_obj is DataMsgCBP) { DataMsgCBP dataMsgCBP = (DataMsgCBP)_obj; Clipboard.SetData(dataMsgCBP.format, dataMsgCBP.content); } else if (_obj is InitFileCBP) { ClipboardFiles.RecvClipboardFiles(Server.CommSocket); } else if (_obj is GetMsgCBP) { IDataObject clipboardData = Clipboard.GetDataObject(); string[] formats = clipboardData.GetFormats(); foreach (string format in formats) { if (format == DataFormats.FileDrop) { continue; } Console.WriteLine("Format: " + format); MsgStream.Send(new DataMsgCBP(format, clipboardData.GetData(format)), Server.CommSocket); } if (Clipboard.ContainsFileDropList()) { if (ClipboardFiles.GetCBFilesSize() > ClipboardFiles.MaxSize) { MsgStream.Send(new MaxSizeCBP(), Server.CommSocket); Object response = MsgStream.Receive(Server.CommSocket); if (!(response is ConfirmCBP)) { return; } } MsgStream.Send(new InitFileCBP(), Server.CommSocket); ClipboardFiles.SendClipboardFiles(Server.CommSocket); MsgStream.Send(new StopFileCBP(), Server.CommSocket); MsgStream.Receive(Server.CommSocket); // wait for an ack } else { MsgStream.Send(new StopFileCBP(), Server.CommSocket); } } }
public override void Update() { try { _obj = null; _obj = MsgStream.Receive(Server._commSocket); if (_obj == null) { Server.State = new WaitingState(); } } catch (SocketException) { } }
public void ReceiveCBMsg() { Message m; int i = 0; while (true) { while (_de.WaitOne()) { lock (_dq) { m = _dq.Dequeue(); } i = ((GetMsgCBP)m).i; //Console.WriteLine("Processing Getting RQ to: " + i); if ((i != 0) && (i != 1) && (i != 2) && (i != 3)) { continue; } if (_ds[i] != null) { _sp[i].CBGetting(); try { MsgStream.Send(m, _ds[i]); //Console.WriteLine("richiesta di ricezione inviata"); do { m = (Message)MsgStream.Receive(_ds[i]); if (m is DataMsgCBP) { DataMsgCBP dataMsgCBP = (DataMsgCBP)m; //Console.WriteLine("ricevuto pacchetto: " + dataMsgCBP.format); System.Windows.Forms.Clipboard.SetData(dataMsgCBP.format, dataMsgCBP.content); } if (m is InitFileCBP) //FILEMSG { /* * System.Windows.Forms.MessageBox.Show("Receiving file/s from server: " + i.ToString() + " .\nYou will be advised when the transfer is completed.", "Starting File/s Transfer", + System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); */ ClipboardFiles.RecvClipboardFiles(_ds[i]); Console.WriteLine("CBP : Received Files."); /* * * System.Windows.Forms.MessageBox.Show("File/s received from server: " + i.ToString() + " .", "Transfer completed", + System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); */ _sp[i].EnableCB(); break; } if (m is MaxSizeCBP) { if (System.Windows.Forms.MessageBox.Show("The size of clipboard's content is greater than MaxSize: " + ClipboardFiles.MaxSize + " \nConfirm the transfer?", "File size exceeding", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { System.Windows.Forms.MessageBox.Show("Receiving file/s from server: " + i.ToString() + " .\nYou will be advised when the transfer is completed.", "Starting File/s Transfer", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); MsgStream.Send(new ConfirmCBP(), _ds[i]); ClipboardFiles.RecvClipboardFiles(_ds[i]); System.Windows.Forms.MessageBox.Show("File/s received from server: " + i.ToString() + " .", "Transfer completed", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); _sp[i].EnableCB(); break; } else { MsgStream.Send(new StopFileCBP(), _ds[i]); _sp[i].EnableCB(); break; } } }while(!(m is StopFileCBP)); _sp[i].EnableCB(); } catch (Exception e) { //Console.WriteLine("Errore nella richiesta CB: chiusura sockets e disconnessione."); System.Windows.Forms.MessageBox.Show("Ops...\nSomething goes wrong during Clipboard Transfer[on Receiving].\nThe connection will be closed.\nTry again later.", "Clipboard Transfer Error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); _sp[i].DisconnectionReq(); Console.WriteLine("Clipboard file transfer error: " + e.Message); } } //end checking socket nullity } //end wait condition } //end infinite loop } //end ReceiveCBMsg