forked from jmonclard/MeosReplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sender.cs
87 lines (75 loc) · 2.32 KB
/
sender.cs
1
2
3
4
5
6
7
8
9
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Net.Sockets;
namespace MeOSReplay
{
internal class Sender
{
IPAddress _ipaddress;
Socket tempSocket;
public IPAddress Ipaddress
{
get { return _ipaddress; }
set { _ipaddress = value; }
}
int _port;
public int Port
{
get { return _port; }
set { _port = value; }
}
internal Sender(IPAddress ip, int port)
{
_ipaddress = ip;
_port = port;
IPEndPoint ipe = new IPEndPoint(_ipaddress, _port);
tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
}
internal bool sendPunch(int codeNumber, int cardNumber, int codeTime)
{
var ms = new MemoryStream(15);
var bw = new BinaryWriter(ms);
bw.Write((byte)0);// type 0=> punch
bw.Write((short)codeNumber);
bw.Write((int)cardNumber);
bw.Write((int)0);//codeday obsolete
bw.Write((int)codeTime);
byte[] barray = ms.ToArray();
bool b = tempSocket.Connected;
if (b)
{
tempSocket.Send(barray, barray.Length, 0);
}
return b;
}
internal bool sendCard(int cardNumber, Punches punches, int zeroTime)
{
var ms = new MemoryStream();
var bw = new BinaryWriter(ms);
bw.Write((byte)64);// type 0=> cardnumber
bw.Write((short)punches.PunchesInfo.Count);// la taille
bw.Write((int)cardNumber);
bw.Write((int)0);//codeday obsolete
bw.Write((int)0);
foreach (int[] p in punches.PunchesInfo)
{
int codeNumber = (int)p[0];
int codeTime = (int)(p[1] + zeroTime)*10;
bw.Write((int)codeNumber);
bw.Write((int)codeTime);
}
byte[] barray = ms.ToArray();
bool b = tempSocket.Connected;
if (b)
{
tempSocket.Send(barray, barray.Length, 0);
}
return b;
}
}
}