/// <summary> /// Create an instance of a JobStep object. /// </summary> /// <param name="blok">Job step record in EBCDIC format.</param> public JobStepTerminationRecord(byte[] blok) { RawDataConverter converter = new RawDataConverter(); try { stepName = converter.GetEBCDIC(0x10, blok, 8); jobName = converter.GetEBCDIC(0x18, blok, 8); duration = (float)converter.GetUINT32(0x20, blok) / 300F; cpuUsed = (float)converter.GetUINT32(0x24, blok) / 300F; ioCount = converter.GetUINT64(0x28, blok); jobDate = converter.GetEBCDIC(0x30, blok, 8); int year = Convert.ToInt32(converter.GetEBCDIC(0x30, blok, 4)); int month = Convert.ToInt32(converter.GetEBCDIC(0x34, blok, 2)); int day = Convert.ToInt32(converter.GetEBCDIC(0x36, blok, 2)); DateTime dt = new DateTime(year, month, day); int hour = Convert.ToInt32(converter.GetEBCDIC(0x38, blok, 2)); int minute = Convert.ToInt32(converter.GetEBCDIC(0x3A, blok, 2)); int second = Convert.ToInt32(converter.GetEBCDIC(0x3C, blok, 2)); stepStart = new DateTime(year, month, day, hour, minute, second); stepStop = stepStart.AddSeconds(duration); partitionId = converter.GetEBCDIC(0x44, blok, 2); } catch (IndexOutOfRangeException ioore) { Debug.WriteLine(ioore.Message); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (connectionResult == ConnectionResult.Connected) { Console.WriteLine($"{tcpConnection.ToString()} Connection established"); //3. Send a raw data packet request. tcpConnection.SendRawData(RawDataConverter.FromUTF8String("HelloWorld", "Hello, this is the RawDataExample!")); //tcpConnection.SendRawData(RawDataConverter.FromBoolean("BoolValue", true)); //tcpConnection.SendRawData(RawDataConverter.FromBoolean("BoolValue", false)); //tcpConnection.SendRawData(RawDataConverter.FromDouble("DoubleValue", 32.99311325d)); ////4. Send a raw data packet request without any helper class //tcpConnection.SendRawData("HelloWorld", Encoding.UTF8.GetBytes("Hello, this is the RawDataExample!")); //tcpConnection.SendRawData("BoolValue", BitConverter.GetBytes(true)); //tcpConnection.SendRawData("BoolValue", BitConverter.GetBytes(false)); //tcpConnection.SendRawData("DoubleValue", BitConverter.GetBytes(32.99311325d)); } }
private void label1_Click(object sender, EventArgs e) { if (!(Ready && enemyReady)) { if (!Ready) { label1.ForeColor = Color.Green; connection.SendRawData("Ready", RawDataConverter.GetBytes(true)); Ready = true; } else { label1.ForeColor = Color.Red; connection.SendRawData("Ready", RawDataConverter.GetBytes(false)); Ready = false; } } }
/// <summary> /// Read each packet /// </summary> /// <param name="data">All of the IP packets, /// this data contains a 12 byte header before each packet /// with a 4 byte length and a 8 byte store clock</param> /// <param name="offset">offset into the data of this packet</param> /// <returns>offset of next packet</returns> private int ReadNextPacket(int offset, byte[] data, out PcapIpPacket packet, bool writeDebug) { RawDataConverter convert = new RawDataConverter(); uint len = convert.GetUINT32(offset, data); DateTime stck = convert.GetDTutc(offset + 4, data);//8 byte STCK int offPack = offset + 12; //int verFromIpHeader = Convert.ToInt32(data[offPack]); ushort lenFromIpHeader = convert.GetUINT16(offPack + 2, data);//2 bytes into the packet header packet = new PcapIpPacket(); if (writeDebug) { Debug.WriteLine( //"[ " + verFromIpHeader.ToString() + " ]" "packet offset = " + offPack.ToString("X").PadRight(8, '0') + //should be 69 for a IPv4 header " : STCK(ss:us) = " + convert.GetUINT64(offset + 4, data).ToString("X") + " = " + convert.GetDTutc(offset + 4, data).ToString("MM-dd-yyyy HH:mm:ss:ffffff") + " : Length = " + len.ToString().PadRight(5, ' ') + "...from IP header = " + lenFromIpHeader.ToString()); } //if (verFromIpHeader == 69)//0x45 = IPv4 with a 40 byte IP header //{ DateTime utcJan11970 = new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime(); //UTC time on Jan 1, 1970 00:00:00 TimeSpan tspan = stck.Subtract(utcJan11970); //The timespan between Jan 1, 1970 00:00:00 and the capture uint tsSeconds = 0; //The number of seconds in the timespan uint tsUseconds = 0; //The usec offset if (tspan.TotalSeconds > 0) { /* tsSeconds must be rounded down with Math.Floor */ tsSeconds = Convert.ToUInt32(Math.Floor(tspan.TotalSeconds)); //Total seconds since Jan 1, 1970 00:00:00 tsUseconds = Convert.ToUInt32(tspan.Milliseconds * 1000); //Usec offset } uint inclLength = len; //# of bytes actually saved in file uint origLength = lenFromIpHeader; //# of bytes in packet when it was captured, in case snaplen trims it /* Get the header and data */ byte[] ipPack = new byte[inclLength]; for (int i = 0; i < ipPack.Length; i++) { ipPack[i] = data[offPack + i]; } packet = new PcapIpPacket(tsSeconds, tsUseconds, inclLength, origLength, ipPack); //}else if(writeDebug){Debug.Write("*ERROR not IPv4*");} return(offPack + Convert.ToInt32(len)); }
public void Demo() { ConnectionResult connectionResult = ConnectionResult.TCPConnectionNotAlive; //1. Establish a connection to the server. TcpConnection tcpConnection = ConnectionFactory.CreateTcpConnection("127.0.0.1", 1234, out connectionResult); //2. Register what happens if we get a connection if (connectionResult == ConnectionResult.Connected) { Console.WriteLine($"{tcpConnection.ToString()} Connection established"); //3. Send a raw data packet request. tcpConnection.SendRawData(RawDataConverter.FromUTF8String("HelloWorld", "Hello, this is the RawDataExample!")); tcpConnection.SendRawData(RawDataConverter.FromBoolean("BoolValue", true)); tcpConnection.SendRawData(RawDataConverter.FromBoolean("BoolValue", false)); tcpConnection.SendRawData(RawDataConverter.FromDouble("DoubleValue", 32.99311325d)); //4. Send a raw data packet request without any helper class tcpConnection.SendRawData("HelloWorld", Encoding.UTF8.GetBytes("Hello, this is the RawDataExample!")); tcpConnection.SendRawData("BoolValue", BitConverter.GetBytes(true)); tcpConnection.SendRawData("BoolValue", BitConverter.GetBytes(false)); tcpConnection.SendRawData("DoubleValue", BitConverter.GetBytes(32.99311325d)); } }
/// <inheritdoc cref="RawDataConverter.ToInt16"/> public static short ToInt16(this RawData rawData) { return(RawDataConverter.ToInt16(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToInt8"/> public static sbyte ToInt8(this RawData rawData) { return(RawDataConverter.ToInt8(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToBoolean"/> public static bool ToBoolean(this RawData rawData) { return(RawDataConverter.ToBoolean(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToDouble"/> public static double ToDouble(this RawData rawData) { return(RawDataConverter.ToDouble(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToSingle"/> public static float ToSingle(this RawData rawData) { return(RawDataConverter.ToSingle(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToUTF16_LittleEndian_String"/> public static string ToUTF16_LittleEndian_String(this RawData rawData) { return(RawDataConverter.ToUTF16_LittleEndian_String(rawData)); }
public static void SendMessge(this ClientConnectionContainer client, string Tag, object data) { client.Send(RawDataConverter.FromUTF8String(Tag, data.ToJson())); }
private void connectionEstablished(Connection con, ConnectionType conType) { int turn = r.Next(2); richTextBox1.Text += $"Connected{con.IPRemoteEndPoint}" + Environment.NewLine; if (p1 == null) { p1 = new Player(con); p1.ready = false; } else { p2 = new Player(con); p2.ready = false; } con.RegisterRawDataHandler("Image", (RawData, connection) => { if (connection == p1.con) { p1.pic = ImageConvert.bytes2Image(RawData.Data); } else { p2.pic = ImageConvert.bytes2Image(RawData.Data); p1.con.SendRawData("image", ImageConvert.image2Bytes(p2.pic)); p2.con.SendRawData("image", ImageConvert.image2Bytes(p1.pic)); if (turn == 1) { p1.FirstTurn = true; p1.con.SendRawData("firstTurn", RawDataConverter.GetBytes(true)); p1.turn = true; } else { p2.FirstTurn = true; p2.con.SendRawData("firstTurn", RawDataConverter.GetBytes(true)); p2.turn = false; } } }); con.RegisterRawDataHandler("Nick", (RawData, connection) => { if (connection == p1.con) { p1.nick = RawData.ToUTF8String(); } else { p2.nick = RawData.ToUTF8String(); p1.con.SendRawData("nick", Encoding.UTF8.GetBytes(p2.nick)); p2.con.SendRawData("nick", Encoding.UTF8.GetBytes(p1.nick)); } }); con.RegisterRawDataHandler("Ready", (RawData, connection) => { if (connection == p1.con) { p1.ready = RawData.ToBoolean(); if (p2 != null) { p1.con.SendRawData("ready", RawDataConverter.GetBytes(p2.ready)); } p2.con.SendRawData("ready", RawDataConverter.GetBytes(p1.ready)); } else { p2.ready = RawData.ToBoolean(); p1.con.SendRawData("ready", RawDataConverter.GetBytes(p2.ready)); p2.con.SendRawData("ready", RawDataConverter.GetBytes(p1.ready)); } }); con.RegisterRawDataHandler("mapUpdate", (RawData, connection) => { char[] newmap = RawData.ToUTF8String().ToArray(); for (int i = 0; i < 9; i++) { map[i] = int.Parse(newmap[i].ToString()); } string mapString = ""; for (int i = 0; i < 9; i++) { mapString += map[i].ToString(); } if (connection == p1.con) { p1.turn = false; p2.turn = true; p1.con.SendRawData("Turn", RawDataConverter.GetBytes(p1.turn)); p2.con.SendRawData("Turn", RawDataConverter.GetBytes(p2.turn)); p2.con.SendRawData("MapUpdate", Encoding.UTF8.GetBytes(mapString)); } else { p2.turn = false; p1.turn = true; p1.con.SendRawData("Turn", RawDataConverter.GetBytes(p1.turn)); p2.con.SendRawData("Turn", RawDataConverter.GetBytes(p2.turn)); p1.con.SendRawData("MapUpdate", Encoding.UTF8.GetBytes(mapString)); } if (checkGameWin() == 1 && p1.FirstTurn) { p1.con.SendRawData("win", RawDataConverter.GetBytes(true)); p2.con.SendRawData("lose", RawDataConverter.GetBytes(true)); map = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; } else if (checkGameWin() == 2 && p2.FirstTurn) { p1.con.SendRawData("win", RawDataConverter.GetBytes(true)); p2.con.SendRawData("lose", RawDataConverter.GetBytes(true)); map = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; } else if (checkGameWin() == 1 && p2.FirstTurn) { p2.con.SendRawData("win", RawDataConverter.GetBytes(true)); p1.con.SendRawData("lose", RawDataConverter.GetBytes(true)); map = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; } else if (checkGameWin() == 2 && p1.FirstTurn) { p2.con.SendRawData("win", RawDataConverter.GetBytes(true)); p1.con.SendRawData("lose", RawDataConverter.GetBytes(true)); map = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; } } ); }
/// <inheritdoc cref="RawDataConverter.ToInt32"/> public static int ToInt32(this RawData rawData) { return(RawDataConverter.ToInt32(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToASCIIString"/> public static string ToASCIIString(this RawData rawData) { return(RawDataConverter.ToASCIIString(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToInt64"/> public static long ToInt64(this RawData rawData) { return(RawDataConverter.ToInt64(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToChar"/> public static char ToChar(this RawData rawData) { return(RawDataConverter.ToChar(rawData)); }
/// <inheritdoc cref="RawDataConverter.ToUnicodeString"/> public static string ToUnicodeString(this RawData rawData) { return(RawDataConverter.ToUnicodeString(rawData)); }
/// <summary> /// Create an instance of a generalized record queue. /// </summary> public ConsoleQueue() { converter = new RawDataConverter(); size = 0; // Set initial size of the queue. }