|
- public void Connect(string address, int port)
5 _- _$ U* O: C" D. L) Z - {" |% ?6 p4 L: f1 z5 P3 i
- if (this.socket.Connected)
/ V0 M( o& g0 H" [! S - {- g4 K; v5 b. S3 R( x/ G
- Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));
2 f) `/ u! w) b3 _ - return;
" }9 T% f4 ^( U6 v6 M. ]! V - }/ w. r) o9 |( G& o l9 q( ^
- this.address = address;
) s0 t5 ^ M6 e2 J4 T: F - this.port = port;- L( g% o2 l* i* h: S; T5 M0 @- E
- MD5 md = MD5.Create();7 y# V6 T, j+ x, z7 y' |5 O
- string a = "12546f1c61454538c45490";
0 p* @: t: Z9 Y( ~& E. U - string a2 = "1252051ca54456902c7054bc";: Y; J/ V2 d6 U3 b* m
- string a3 = "66610b45455576";
/ x, ?9 o5 t- D* S7 n7 D! B - string a4 = "4582fdgs4545wr42saf1";7 [# z6 i* s+ U+ _. z0 E
- byte[] bytes = Encoding.Default.GetBytes(address);
) ^9 l3 e; x4 s+ c9 o5 T) S - byte[] array = md.ComputeHash(bytes);$ w( O) ?' i R- G) l
- string text = string.Empty;( Y# z& I/ }4 Y+ G) @
- for (int i = 0; i < array.Length; i++)
$ f4 U: q& ]6 e U+ N1 Z5 s - {
0 H' ?7 {: F7 h& S# {0 M" m - text += array[i].ToString("x6");
8 V4 G1 c7 d; Y( R8 { - }& E0 @: ~1 E, o- R& c! |# L
- byte[] bytes2 = Encoding.Default.GetBytes(text);* h6 a1 b# O2 c8 I3 u. I9 Q
- byte[] array2 = md.ComputeHash(bytes2);8 W# U, c9 H& P5 i* b2 t
- string text2 = string.Empty;
6 y0 d |4 ?8 x4 I9 T - for (int j = 0; j < array2.Length; j++)
$ r4 |0 `4 k" K( `, e& h - {
8 U+ z, R8 j: f5 b - text2 += array2[j].ToString("x2");
$ \+ ~, b' P* H# B6 \" z; E - }, x; r1 m+ }' a
- if (!(a == text2) && !(a2 == text2) && !(a3 == text2))4 q" i8 P3 g+ E. P/ k
- {
" Q9 L0 }% b1 |* q* @4 v - if (!(a4 == text2))
( m; E8 g j, y. g - {: j( W2 M' z2 ^: a
- this.Disconnect();! m7 U* H z6 N) A
- return;
) f T% d& z& M6 s* y3 Z5 I - }
* D0 ^' l4 ~! r- |" H5 H. p) @ - }
% K* I V+ C8 [2 p8 W: M' e4 w - try9 y% G8 A0 A* q1 I
- {
, T" E% c' E9 O: j - Log.Debug("Socket尝试建立连接");. @$ O3 S. W* l
- this.ConnectStatus = ConnectStatusEnum.HasConnect;
, _& \8 D2 V9 y; |' w5 v - this.connetTime = Time.time;- ^& M* I3 t, B1 E# w) I
- this.result = this.socket.BeginConnect(address, port, null, null);& N9 S: \- x5 X3 C; m$ w
- TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
( p, c' U, ^3 e" M - }: I6 d* h4 w3 W% L$ \9 t( C: n5 Y7 L
- catch (SocketException ex)
3 x& H4 J1 s0 A1 F - {+ q ]( Z1 E |8 C& _; X; F
- this.result = null;
7 W- k# E* W& S3 |8 M7 b - this.socket.Close();
- o; `9 G( l. t1 \2 `: _ - Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));5 j2 {' t2 h1 N# i5 r
- this.Disconnect();
. q* h4 ~$ J0 T1 ?% `. f - }
) N6 l' b$ c9 h* I% h: ]) r1 _3 \ - }
复制代码
. S, g' \& I5 t$ R [ x' j2 o6 b9 ^4 I" d6 O8 \( p
}+ a; B4 e |3 k+ \" o6 c- Y- address=ip地址
3 O" d! y) C6 w$ d* G. I3 ~/ c - ' a; }& l+ c3 E: T6 K
- byte[] bytes = Encoding.Default.GetBytes(address);
, I! ]) J/ _2 @) E4 K; T - byte[] array = md.ComputeHash(bytes);1 f3 x! w8 u7 o3 V
- string text = string.Empty;7 E9 }4 x, }& h0 v: U3 ~
- for (int i = 0; i < array.Length; i++)
$ r( R- d b: n. E7 x# e! t3 E - {
) \" a/ [7 Y3 n9 @4 t - text += array.ToString("x6");
# M% `! A' `5 f) a3 Y - }
- ?- _+ H& L8 N6 l0 B! r! x - byte[] bytes2 = Encoding.Default.GetBytes(text);
9 `# y& T4 H0 F5 e - byte[] array2 = md.ComputeHash(bytes2);" d' @- L+ Z+ B3 C# Q, e$ N. x
- string text2 = string.Empty;
* h/ h" i: x! B' {; E/ w+ W: X& f - for (int j = 0; j < array2.Length; j++)
, \/ ?2 h/ G. h, R* I - {; A- q b5 i( [ ^
- text2 += array2[j].ToString("x2");
( m+ W8 Z a6 j, ~) b: O* V - }
2 `0 h7 G8 ~6 j9 Y O - text2就是最终密文
复制代码 ! a* J5 a6 p2 E3 Q6 t6 [$ A
5 x, A5 O9 ~, v' p |
|