- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace GisClient
{
class EntryPoint
{
static void Main()
{
TcpClient TcpCli = new TcpClient("127.0.0.1", 15800);
NetworkStream ns = TcpCli.GetStream();
PacketStructure obj = new PacketStructure();
obj.CommandOptions = 0x80; //What's this shit??? 0x80 , what's Encoding??? What 0x80 equals to?
obj.Write2Net(ns);
obj.ReadFromNet(ns);
}
}
class PacketStructure
{
UInt32 PacketId = 0x35534947;
Guid UserId = new Guid();
public byte CommandOptions = 0;
UInt32 CommandSize = 0;
byte[] Reserved = new byte[3];
public void Write2BufferStream(MemoryStream ms)
{
//PacketId || Length - 4 || Type - UInt32
ms.Write(BitConverter.GetBytes(PacketId), 0, 4);
//UserId || Length - 16 || Type - byte[16]
ms.Write(UserId.ToByteArray(), 0, 16);
//Command Options || Length - 1 || byte
ms.Write(BitConverter.GetBytes(CommandOptions), 0, 1);
//Command Size || Length - 4 || Int32
ms.Write(BitConverter.GetBytes(CommandSize), 0, 4);
//Reserved space || Length - 3 || byte[3]
ms.Write(Reserved, 0, 3);
//CRC32 - control summary
ms.Write(BitConverter.GetBytes(CRC32.BytesCrc(ms.ToArray())), 0, 4);
}
public void Write2Net(NetworkStream ns)
{
MemoryStream ms = new MemoryStream();
Write2BufferStream(ms);
byte[] A = ms.ToArray();
ns.Write(A, 0, (int)ns.Length);
}
public void ReadFromNet(NetworkStream ns)
{
byte[] B = new byte[32];
ns.Read(B, 0, (int)ns.Length);
PacketId = BitConverter.ToUInt32(B, 0); //??????? lolwhat?????!!!!!111
byte[] C = new byte[16];
for (int i = 0; i < 16; i++)
{
C[i] = C[i + 4];
}
foreach (int i in C)
{
Console.WriteLine(i);
Console.ReadLine();
}
UserId = new Guid(C);
CommandOptions = B[20]; // Why no BitConverter?????!!!!!
CommandSize = BitConverter.ToUInt32(B, 21); // The end of CommandSize IS NOT SET!!!!1111
for (int i = 0; i < 3; i++) Reserved[i] = B[i + 25]; // A[0] = Packet[0 + 25] IF i = 0 THEN i++
Console.ReadLine();
}
}
}
Код с работы, вот так вот мы отслыаем и принимаем пакеты по TCP.
Комменатрии особенно доставляют удовольствие :)