|
- public void Connect(string address, int port)
) p5 h% B9 @4 N/ I6 S$ I0 Q, C6 E - {
6 q5 z- o+ [5 n6 x5 u2 W3 M) q/ _ - if (this.socket.Connected)
, V8 @0 {( S9 k0 H0 o, H$ x4 C - {, g/ l& m9 M- i6 Y& ?5 X
- Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));
* t9 K; P# A# W6 ~& y5 N/ j. M - return;6 \# o, h, F% i3 _; E$ K; T; S% w& ~
- }
* A/ ]; \$ { h; Z( ~& J - this.address = address;% ^7 I* D( ?$ J$ o* C; v7 E- q
- this.port = port;
b0 M! r3 ?+ D+ }- ~" Q' J - MD5 md = MD5.Create();
9 C" M, l/ x' [, M, {" g - string a = "12546f1c61454538c45490";8 L( \$ W& p! ^2 ?! R5 b. |# M
- string a2 = "1252051ca54456902c7054bc";# Y$ U, ]/ c8 i5 @/ z! C
- string a3 = "66610b45455576";
; N z. V# h- S+ X# |+ M - string a4 = "4582fdgs4545wr42saf1";. h0 i( q. L2 S+ l }; ?# r
- byte[] bytes = Encoding.Default.GetBytes(address);
, V9 ~4 F6 i3 B1 m: g( @7 _ - byte[] array = md.ComputeHash(bytes);
* `, |0 R3 W" s' _+ Q, ]% P - string text = string.Empty;) V4 ?8 z" c7 D$ b( N
- for (int i = 0; i < array.Length; i++)
5 n, y( Z9 j' \6 ^- p+ O - {
& x/ [; y% ~) E7 D: B& r3 A! y - text += array[i].ToString("x6");2 y" ^ |8 P! s; I
- }
8 M; V3 A; n7 @* H - byte[] bytes2 = Encoding.Default.GetBytes(text);
, c8 \( ]' b, ?8 _ - byte[] array2 = md.ComputeHash(bytes2);. }" w8 D2 J, r
- string text2 = string.Empty;" Q1 n% S2 z8 G! y3 z
- for (int j = 0; j < array2.Length; j++)
& I5 b/ t; ^* ?& {' }! S - {
0 a& z# A! }# c! G - text2 += array2[j].ToString("x2");3 W: e, J1 P e0 ^
- }* k# N/ a X" \8 P4 `
- if (!(a == text2) && !(a2 == text2) && !(a3 == text2))
# e$ p: u- a, t2 T - {
$ s3 J' G0 p e6 y1 n7 Z - if (!(a4 == text2))
8 y3 Q0 Y1 U! a. }4 K5 ` - {
2 ?3 }& w. k: i; ]# B7 d! t - this.Disconnect(); F3 |) a* t4 {" i( ~
- return;
v: f: X9 k4 O( s7 Z - }: b1 t0 U, c6 d/ o/ l6 V: ~7 I
- }" P% w D: j- h1 p$ N! f
- try4 D, i5 V7 ` F V; t( z
- {
) S( R$ W& M8 Q! U( F - Log.Debug("Socket尝试建立连接");
! I! @/ c0 X3 V& K5 o. u - this.ConnectStatus = ConnectStatusEnum.HasConnect;4 [: V) h6 Y5 ? Z5 a7 |
- this.connetTime = Time.time;* D3 B& B$ I* k6 b' Y& n
- this.result = this.socket.BeginConnect(address, port, null, null);7 y$ ]3 w- d( \; E, A7 }
- TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
6 J' Y B; V( s - }0 g% A$ a+ k* v0 i3 W
- catch (SocketException ex) c0 s4 x) A. ^9 Z8 L' A0 z( j
- {, V4 p# a2 y, H7 h: F$ u5 b
- this.result = null;3 T3 a; ]0 R" n6 f3 ^ v+ W
- this.socket.Close();
) s- M5 e! P, Y2 U. p1 ] - Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));9 J( N1 G9 z" ?, V
- this.Disconnect();
: m% e& L* z1 D% f' [5 ~: T - }
3 E% S8 |# a* }- H8 c! D - }
复制代码 ! Y1 S' Y* Z; X0 n& t
3 n# W7 o( W% u; R9 J9 ^0 b
+ R6 w5 i; K5 X0 A) n: [ N) ^3 D2 C- address=ip地址
7 e: {- L# O6 O0 K+ ^7 e [
7 w4 U' m$ x* i# { ]3 ]- byte[] bytes = Encoding.Default.GetBytes(address); [7 O5 F( b8 s- y
- byte[] array = md.ComputeHash(bytes);
5 `/ `( S) C; H* ~ - string text = string.Empty;
( @. k. c# U6 X' h d- }+ F5 L* p - for (int i = 0; i < array.Length; i++): M' _' B1 ~4 d
- {+ m/ {* a U5 m/ p3 _
- text += array.ToString("x6");
; i% b9 v& G: j7 A2 ~ - }
! l/ O6 d+ w' w5 p# B - byte[] bytes2 = Encoding.Default.GetBytes(text);- e8 |6 b5 g9 E* w) b
- byte[] array2 = md.ComputeHash(bytes2);$ L/ f& }4 P( t! e; h
- string text2 = string.Empty;
/ O. p: X- ^' W- @( I& e - for (int j = 0; j < array2.Length; j++)
" d$ \ `& c# i+ Y5 z; w/ s! T9 @( x - {7 |9 C* W5 |: M8 c1 D; u: e+ G
- text2 += array2[j].ToString("x2");
3 [/ I1 ~+ e/ V2 ]$ }; p# r5 L - }: {) |+ n' E, o* R% m; ?' h
- text2就是最终密文
复制代码 3 X! \1 R( D/ m N$ @
7 J- u/ u" u( [' N: f8 U* ?( L1 } |
|