/// <summary> /// Send a list of results to server /// </summary> /// <param name="ip">Server IP</param> /// <param name="port">Server Port</param> /// <param name="listResults">List of results to send</param> public DataResult(string ip, int port, List<Task> listResults) { List<byte[]> listWorksToSend = new List<byte[]>(); listResults.Sort(); /*Connect to client*/ Sender s = new Sender(ip, Convert.ToInt32(port)); foreach (Task item in listResults) { /*Add info of data*/ if (item.data != null) { PacketInfo packetInfo = new PacketInfo(Command.Result, item.noPacket, "", item.data.Length,item.secondSince1970,item.issueNumber); listWorksToSend.Add(packetInfo.ToByte()); /*Add data*/ listWorksToSend.Add(item.data); } } /*Assembly the packets*/ PacketAssembler packetAssembler = new PacketAssembler(); byte[] dataToSend = packetAssembler.Assemble(listWorksToSend); listResults.Clear(); /*Send data to client*/ s.send(dataToSend); }
/// <summary> /// Send a list of results to server /// </summary> /// <param name="ip">Server IP</param> /// <param name="port">Server Port</param> /// <param name="listResults">List of results to send</param> public DataResult(string ip, int port, List <Task> listResults) { List <byte[]> listWorksToSend = new List <byte[]>(); listResults.Sort(); /*Connect to client*/ Sender s = new Sender(ip, Convert.ToInt32(port)); foreach (Task item in listResults) { /*Add info of data*/ if (item.data != null) { PacketInfo packetInfo = new PacketInfo(Command.Result, item.noPacket, "", item.data.Length, item.secondSince1970, item.issueNumber); listWorksToSend.Add(packetInfo.ToByte()); /*Add data*/ listWorksToSend.Add(item.data); } } /*Assembly the packets*/ PacketAssembler packetAssembler = new PacketAssembler(); byte[] dataToSend = packetAssembler.Assemble(listWorksToSend); listResults.Clear(); /*Send data to client*/ s.send(dataToSend); }
/// <summary> /// Verify if a adress IP is reachable /// </summary> /// <param name="ipAddress">IP to test</param> /// <param name="port">port to send</param> /// <returns>Is reachable</returns> public static bool IsIpReachable(this string ipAddress, int port) { if (ipAddress != "") { Sender sender = new Sender(ipAddress, port); return sender.send(new byte[1]); //Send without data } else return false; }
/// <summary> /// Send alive packet /// </summary> private void sendAlivePacket() { if (working) { PacketInfo packetInfo = new PacketInfo(Command.AliveClient, 0, "", 0, (int)timer.Interval, 0); byte[] data = packetInfo.ToByte(); Sender s = new Sender(serverIP, serverPort); s.send(data); } }
/// <summary> /// Send initialized data /// </summary> /// <param name="ip">Server IP</param> /// <param name="port">Server port</param> public static void sendInitialized(string ip, int port) { /*Connect to client*/ Sender s = new Sender(ip, Convert.ToInt32(port)); /*Add info of data*/ PacketInfo packetInfo = new PacketInfo(Command.Initialized, 0, "", 0, 0, 0); /*Send data to client*/ s.send(packetInfo.ToByte()); }
/// <summary> /// Send initialized data /// </summary> /// <param name="ip">Server IP</param> /// <param name="port">Server port</param> public static void sendInitialized(string ip, int port) { /*Connect to client*/ Sender s = new Sender(ip, Convert.ToInt32(port)); /*Add info of data*/ PacketInfo packetInfo = new PacketInfo(Command.Initialized, 0, "", 0,0,0); /*Send data to client*/ s.send(packetInfo.ToByte()); }
/// <summary> /// Verify if a adress IP is reachable /// </summary> /// <param name="ipAddress">IP to test</param> /// <param name="port">port to send</param> /// <returns>Is reachable</returns> public static bool IsIpReachable(this string ipAddress, int port) { if (ipAddress != "") { Sender sender = new Sender(ipAddress, port); return(sender.send(new byte[1])); //Send without data } else { return(false); } }
/// <summary> /// Send data init to server /// </summary> /// <param name="ip">IP of server</param> /// <param name="port">Listen port of server</param> /// <param name="init">Packet Init</param> public DataInit(string ip, int port, Init init) { try { List<byte[]> listPacketInit = new List<byte[]>(); /*Connect to client*/ Sender s = new Sender(ip, Convert.ToInt32(port)); byte[] dataToSend = init.ToByte(); /*Add info of data*/ PacketInfo packetInfo = new PacketInfo(Command.Init, 0, "", dataToSend.Length,0,0); listPacketInit.Add(packetInfo.ToByte()); /*Add data*/ listPacketInit.Add(dataToSend); /*Assembly the packets*/ PacketAssembler packetAssembler = new PacketAssembler(); dataToSend = packetAssembler.Assemble(listPacketInit); /*Send data to client*/ s.send(dataToSend); } catch { } }
/// <summary> /// Send data init to server /// </summary> /// <param name="ip">IP of server</param> /// <param name="port">Listen port of server</param> /// <param name="init">Packet Init</param> public DataInit(string ip, int port, Init init) { try { List <byte[]> listPacketInit = new List <byte[]>(); /*Connect to client*/ Sender s = new Sender(ip, Convert.ToInt32(port)); byte[] dataToSend = init.ToByte(); /*Add info of data*/ PacketInfo packetInfo = new PacketInfo(Command.Init, 0, "", dataToSend.Length, 0, 0); listPacketInit.Add(packetInfo.ToByte()); /*Add data*/ listPacketInit.Add(dataToSend); /*Assembly the packets*/ PacketAssembler packetAssembler = new PacketAssembler(); dataToSend = packetAssembler.Assemble(listPacketInit); /*Send data to client*/ s.send(dataToSend); } catch { } }