1 |
sf-demisephi |
1.1 |
|
2 |
|
|
using System; |
3 |
|
|
using System.IO; |
4 |
|
|
using System.Net; |
5 |
|
|
using System.Net.Sockets; |
6 |
|
|
using System.Threading; |
7 |
|
|
|
8 |
|
|
using System.Text; |
9 |
|
|
|
10 |
|
|
namespace _olbaid_websockets |
11 |
|
|
{ |
12 |
|
|
class MainClass |
13 |
|
|
{ |
14 |
|
|
public static Socket connectionSocket; |
15 |
|
|
public static void onClientConnect (IAsyncResult asyn){ |
16 |
|
|
Console.WriteLine("Socket accepted"); |
17 |
|
|
Socket client = connectionSocket.EndAccept(asyn); |
18 |
|
|
connectionSocket.BeginAccept(new AsyncCallback(onClientConnect), null); |
19 |
|
|
Client c = new Client(client); |
20 |
|
|
Thread thread = c.createThread(); |
21 |
|
|
thread.Start(); |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
public static void Main (string[] args) |
25 |
|
|
{ |
26 |
|
|
|
27 |
|
|
if (args.Length == 1){ |
28 |
|
|
ASCIIEncoding encoding = new ASCIIEncoding(); |
29 |
|
|
BinaryReader br = new BinaryReader(File.Open(args[0],FileMode.Open)); |
30 |
|
|
Int32 len; |
31 |
|
|
byte [] buffer; |
32 |
|
|
len = br.ReadInt32(); |
33 |
|
|
|
34 |
|
|
buffer = br.ReadBytes(len); |
35 |
|
|
|
36 |
|
|
string key1=encoding.GetString(buffer,0,len); |
37 |
|
|
//Console.WriteLine(key1 + " " + len); |
38 |
|
|
len = br.ReadInt32(); |
39 |
|
|
buffer = br.ReadBytes(len); |
40 |
|
|
|
41 |
|
|
string key2=encoding.GetString(buffer,0,len); |
42 |
|
|
//Console.WriteLine(key2 + " " + len); |
43 |
|
|
|
44 |
|
|
len = br.ReadInt32(); |
45 |
|
|
Console.WriteLine(" Z" + len + "X"); |
46 |
|
|
byte [] l8b=br.ReadBytes(8); |
47 |
|
|
byte [] hixieResp = Client.calcHixieResponse(key1,key2,l8b); |
48 |
|
|
Console.Write ("hixie: " ); |
49 |
|
|
for (int i = 0;i<hixieResp.Length;++i){ |
50 |
|
|
Console.Write("{0:D},",hixieResp[i].ToString()); |
51 |
|
|
} |
52 |
|
|
Console.WriteLine(" "); |
53 |
|
|
return; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
connectionSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
57 |
|
|
connectionSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); |
58 |
|
|
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, 13327); |
59 |
|
|
// Bind to local IP Address |
60 |
|
|
connectionSocket.Bind(ipLocal); |
61 |
|
|
// Start Listening |
62 |
|
|
connectionSocket.Listen(1000); |
63 |
|
|
// Creat callback to handle client connections |
64 |
|
|
connectionSocket.BeginAccept(new AsyncCallback(onClientConnect), null); |
65 |
|
|
|
66 |
|
|
while (1==1){ |
67 |
|
|
Thread.Sleep(10000); |
68 |
|
|
} |
69 |
|
|
/* |
70 |
|
|
* Console.WriteLine("There is some connection awaiting"); |
71 |
|
|
Client client = new Client(listener.AcceptTcpClient()); |
72 |
|
|
Thread thread = client.createThread(); |
73 |
|
|
thread.Start(); |
74 |
|
|
} |
75 |
|
|
*/ |
76 |
|
|
//} |
77 |
|
|
return; |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
} |