|
- public void Connect(string address, int port)+ G J, e" T0 V4 }0 L
- {
, n ], E( M# W, ^4 y0 g( } - if (this.socket.Connected)) ~7 O. Y+ ~* [
- {6 M) Q# c! k; m) j) f1 p
- Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));
# k' J. L& ^3 y9 S$ S - return;; b% h7 C" v1 U+ Z, Z
- }
) O8 t- B" S3 v. T- B. I - this.address = address;
2 t( u4 j6 | f! k6 L7 _$ Q - this.port = port;: q# Y; U4 G' T, @7 t3 y& X
- MD5 md = MD5.Create();
6 X& }2 y/ i ` - string a = "12546f1c61454538c45490"; S) }( [) _2 q; e/ [' l C
- string a2 = "1252051ca54456902c7054bc";5 w& l8 x; M$ G+ f9 X4 R
- string a3 = "66610b45455576";! Z- m( M {! d7 Q7 S% j# g
- string a4 = "4582fdgs4545wr42saf1";! W9 w# y r3 l: m n. s& ~' L5 |* r
- byte[] bytes = Encoding.Default.GetBytes(address);; ]# d; }6 p8 O% R; Q2 ?
- byte[] array = md.ComputeHash(bytes);5 _/ W* t$ V0 ~. o, v
- string text = string.Empty;
. N4 l' Z# g7 O+ j( n8 Z0 D - for (int i = 0; i < array.Length; i++)- G4 |' Q, a1 y' s% f
- {+ [2 a$ y: K3 i! @: v* h
- text += array[i].ToString("x6");" I$ e2 `. [6 |+ f- k2 U
- }
3 Y+ W6 N% p" L - byte[] bytes2 = Encoding.Default.GetBytes(text);4 @* `" X+ |, v6 Q1 I; W
- byte[] array2 = md.ComputeHash(bytes2);
. d4 |. B. q6 \! Q - string text2 = string.Empty;
4 f2 ~; V4 L/ T8 M# o" E7 h - for (int j = 0; j < array2.Length; j++)% M: {/ `! \8 B* M( c8 v
- {
9 i& t1 Y' g# m - text2 += array2[j].ToString("x2");8 o1 |$ r' }: r) o; R
- }' |# d3 M% L" d2 p: |. E
- if (!(a == text2) && !(a2 == text2) && !(a3 == text2))4 c; \' M$ w) L: k! Z; Y ]
- {
' G% d! L! U* |+ X - if (!(a4 == text2))
* T/ U" i+ l, T6 r; a3 z - {
# |: D5 n# \$ E' N - this.Disconnect();' ~% Y/ D( w; ]: Y
- return;; t X# V1 o0 w3 C( B
- }4 V, g. G5 ?4 f) v; @
- }
7 n2 T7 R# [; g3 h9 x2 c; O9 I - try* U2 ?, d8 v. G/ h$ B; ^
- {
7 A5 n1 r& A1 t* I - Log.Debug("Socket尝试建立连接");% K" Z4 W5 [. h
- this.ConnectStatus = ConnectStatusEnum.HasConnect;+ J2 ?" D' u" Z$ o" M6 T8 {
- this.connetTime = Time.time;
' [: Q" d& }% N! Z; g" { - this.result = this.socket.BeginConnect(address, port, null, null);6 j2 d$ A/ @ `5 i" M
- TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
1 C% _1 Y% K& s. j! q - }4 T9 Y! K4 c0 w( Z! t3 B
- catch (SocketException ex), x0 x$ @+ k: ?9 A4 ^" V
- {
! o( }) ~! t( ]; m/ n - this.result = null;
3 N+ W4 L Z& r( C+ z+ @" x - this.socket.Close();
4 N3 ?$ o7 h" E: x+ E; G - Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));( j9 E4 v) u. q, @
- this.Disconnect();! f' [7 K' k" x! {% l; n7 H
- }2 b% x/ f* t. N n* A5 S& k
- }
复制代码 5 Y+ s R$ A6 S9 @$ y
v7 |8 s! x# O# i4 p T5 g1 ^& H/ x6 f P4 Z2 X+ X& C/ g
- address=ip地址
/ [: I- m' R5 T/ `" z" L5 z: s - $ w3 c! O, Q+ G4 [6 J8 r6 j) {
- byte[] bytes = Encoding.Default.GetBytes(address);, x5 o, }. M9 O
- byte[] array = md.ComputeHash(bytes);: S V6 h& k4 L
- string text = string.Empty;$ |, v' d' T8 l: I! X
- for (int i = 0; i < array.Length; i++)$ o2 E) U/ e# o4 a
- {
: Y9 E1 D/ \2 w7 N: r" ] - text += array.ToString("x6");
; a+ b9 } D% ~/ t/ x, Q - }
8 _3 y- F7 q$ K# D0 [7 [9 B) l - byte[] bytes2 = Encoding.Default.GetBytes(text);
; J; r" w( z9 ?. [7 {. V$ g/ E - byte[] array2 = md.ComputeHash(bytes2);0 c, Z% o+ ?1 o5 c
- string text2 = string.Empty;! x4 r) b0 {+ l: I5 `$ D7 k
- for (int j = 0; j < array2.Length; j++)' G4 v% U% N8 e0 P0 l) M
- {
' _+ v! t" Z( ^6 x6 T! P* r/ v- ?; Q( V - text2 += array2[j].ToString("x2");
- F% E/ k5 X$ W- T5 |; R; ]/ b8 k - }/ X% Y- L% c8 U1 m
- text2就是最终密文
复制代码 9 J% j7 e2 O2 w0 V3 A
5 L1 I i; Z- S' ?3 l# M: j6 G1 f
|
|