|
- public void Connect(string address, int port)5 H- ~7 _& e1 {6 d, I
- {
8 }( h" ]2 t6 U( V! r' P - if (this.socket.Connected)# {4 I6 q- I" _
- {
' q% {* }, }, F - Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));0 M/ g0 _6 `& a" `& V1 K
- return;
' H* s* W$ M1 m, J- c4 T* o - }- _3 h# e% ^! [: [
- this.address = address;
/ h& ?- w% {6 Z& R9 a: O - this.port = port;9 r a* _: ~& a W& C8 l% A$ s0 g
- MD5 md = MD5.Create();+ v; g* j( x/ @ y& {. @7 n
- string a = "12546f1c61454538c45490";
4 b1 H1 z/ b: J) ] - string a2 = "1252051ca54456902c7054bc";( u. R" d& B/ k, J; D4 D4 s
- string a3 = "66610b45455576";: a7 J5 C" T3 T; [% P3 O J. |) E
- string a4 = "4582fdgs4545wr42saf1";; U$ t9 R& U5 X6 O$ I* B- V
- byte[] bytes = Encoding.Default.GetBytes(address);
. L# u) M( M6 o8 M. {6 F - byte[] array = md.ComputeHash(bytes);. |8 A0 n% y! m& t
- string text = string.Empty;
- M! ]6 s+ A& Y) H6 B; F! ` - for (int i = 0; i < array.Length; i++), j" A; l6 m \* U6 G Z6 Y6 f
- {) R) \- \) `0 z: L. }# X
- text += array[i].ToString("x6");
0 P* o) V& [9 w/ G - }
6 F, W7 m! Y# F - byte[] bytes2 = Encoding.Default.GetBytes(text);+ G2 b7 |0 a; b' J. E7 t
- byte[] array2 = md.ComputeHash(bytes2);
# c/ \: j2 r/ m7 e% }3 ? - string text2 = string.Empty;
# C7 Y8 y7 a1 G- S& \7 N4 Y - for (int j = 0; j < array2.Length; j++)" \7 {( ~# F3 A& \" M) v5 Y/ l
- {- i2 O6 Y0 y* p' x h! J2 j/ C+ }
- text2 += array2[j].ToString("x2");
" h3 C. H5 j9 v - }& X/ u: \5 P0 k1 Q) t. J# _/ q3 P" T
- if (!(a == text2) && !(a2 == text2) && !(a3 == text2))
+ t8 E9 s R# f- F - {5 _6 N2 N" P3 r
- if (!(a4 == text2))
6 d6 ^ f0 x5 [ - {' E2 \+ E+ u1 F& r! T
- this.Disconnect();
, `' I( C' J4 E& J( K - return;( A3 X6 r) R* f% k8 ]) c5 m
- }
( ?- Y3 p* d: v - }1 ^7 b% @0 l# o
- try( q/ V/ X1 F% V0 v3 C
- {9 F$ n+ O2 i5 D" {# S" J
- Log.Debug("Socket尝试建立连接");, x, ?) R' f- I7 d) e
- this.ConnectStatus = ConnectStatusEnum.HasConnect;% |, o' |- L4 [4 ^! u
- this.connetTime = Time.time;2 Z) s( a; Z- ~7 X8 S) \8 j
- this.result = this.socket.BeginConnect(address, port, null, null);, H: _1 g9 f; q- s% U% x+ X
- TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
# Y% R0 ^7 H7 P# V, V( ]/ G ~ - }9 d% y8 @( g, k1 g) K; j( |
- catch (SocketException ex)
9 u7 {8 t. l2 C4 M. i' X - {
; a# `% p* c- |; e9 t2 _ - this.result = null;
1 K$ [$ h. S6 F! r0 | - this.socket.Close();: M4 ~) _7 _3 `6 Q/ y
- Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));
}2 v& E1 b$ I- X2 m( N - this.Disconnect();
/ w- j @2 e! X9 `2 |/ b2 ]" Y7 }* M - }7 r; ]: a% {: y7 f N& u* `- ~
- }
复制代码
* v5 u! Y0 f3 O9 {2 W) {) ~7 e3 ^1 [/ G+ o6 J* E* S0 i4 H
! D7 k; `- J4 |6 U" c9 P
- address=ip地址, b7 o1 o6 S8 l
- $ T t' \4 {" ~7 T+ ]
- byte[] bytes = Encoding.Default.GetBytes(address);. [9 i) n9 e) s3 p: e% n
- byte[] array = md.ComputeHash(bytes);
4 P) F; S1 b8 W: Z% z3 e l - string text = string.Empty;+ {# j) D$ y0 C. s* Y' M- @
- for (int i = 0; i < array.Length; i++)
9 a4 J7 ^ ?1 k! I - {9 }# A* v; H/ ~
- text += array.ToString("x6");
) W! Z! H1 o6 P( W - }3 S6 t' ^- M5 m1 a6 g
- byte[] bytes2 = Encoding.Default.GetBytes(text);
, d0 V2 ~" Y; M/ l* M - byte[] array2 = md.ComputeHash(bytes2);) J% w- G, i! o/ Y* A) ~
- string text2 = string.Empty;; O6 d6 I( j& V! ^* S/ r: a
- for (int j = 0; j < array2.Length; j++)
7 ]$ e7 Z8 j4 `6 ^! H$ @ - {3 O; L9 P8 P4 g' [4 \2 v
- text2 += array2[j].ToString("x2");
! l q6 a8 D& U - }
0 r7 o0 @; B* B7 U- l - text2就是最终密文
复制代码 # W. n ~8 ]6 r! n b/ N9 q
1 O* z9 Q! W" l D |
|