|
- public void Connect(string address, int port)) O; I% Q0 K. V! h; u+ x
- {7 v2 k) \% R; B- s$ s8 o. Y% ]
- if (this.socket.Connected)
( B7 k$ v" L" [, n' a- T4 @ - {
8 {8 k" ?1 M% f2 M' [4 @: m" |5 q - Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));& N& w5 u: r( Z
- return;7 b- g+ Q4 \ r, D6 |0 c) ^
- }
* J, [; G' e6 h ~( R9 y9 C - this.address = address;
, C: y5 U) j& S) T( E! k( R% E1 \ - this.port = port;
9 D3 ~6 R1 B" _ i5 P9 d& U - MD5 md = MD5.Create();
7 y% D4 ?4 e( z" R$ v - string a = "12546f1c61454538c45490";) z/ \5 _4 y$ m* D& R% _
- string a2 = "1252051ca54456902c7054bc";
1 ]# T# e; y5 I2 {; O f - string a3 = "66610b45455576";
: D" |5 K+ M. G' |* x2 G+ i1 v# D - string a4 = "4582fdgs4545wr42saf1";9 [ x5 i- a8 Z
- byte[] bytes = Encoding.Default.GetBytes(address);
9 {& L) S b0 G) c. q( s6 \ - byte[] array = md.ComputeHash(bytes);6 G5 Q" I7 a" F T6 ?
- string text = string.Empty;
6 J! h; V% D( }3 z) Z - for (int i = 0; i < array.Length; i++)) S- a! e' M. N( [5 a3 Y- s5 v9 W# e
- {: _! D h4 f% B! M, B( _ Z, ~
- text += array[i].ToString("x6");
2 I6 i8 y" Q- ]3 R6 o+ r - }( U# o1 `" m" ~) |+ ^* m; w
- byte[] bytes2 = Encoding.Default.GetBytes(text);5 @8 `2 o0 ~9 B
- byte[] array2 = md.ComputeHash(bytes2);
% A. l2 t0 k* p9 v3 Z - string text2 = string.Empty;
" b# B7 S+ ?+ \# m2 Q - for (int j = 0; j < array2.Length; j++)
, M: l! h9 a I8 i8 X - {. R3 X" @' g7 b) G' D0 K
- text2 += array2[j].ToString("x2");0 k) d7 c" n5 j y% i$ R
- }" n# M: D- u. r( S
- if (!(a == text2) && !(a2 == text2) && !(a3 == text2))
* m) \2 h, [% {6 F - {4 S8 {; z- L4 ^4 b
- if (!(a4 == text2))
" \& d4 _3 B& P; \ o - {, D1 n/ G8 Y8 L1 Q, q6 q5 c F3 m
- this.Disconnect();4 y# N0 l) W: o2 ?3 m+ A$ }
- return;. l% H2 r. f% o+ `
- }( G9 Q, n, w: z$ z' \" C
- }
: |- B; F3 F$ ?* f - try9 R* p* b4 M* L# q. r
- {% h: ^6 q! D# H' \
- Log.Debug("Socket尝试建立连接");4 `. w" H' {- a
- this.ConnectStatus = ConnectStatusEnum.HasConnect; ~; e0 ]5 W; s# E+ ^2 ~ ?
- this.connetTime = Time.time;% p: W# k: {4 A- G7 p2 k" I5 r
- this.result = this.socket.BeginConnect(address, port, null, null);
5 R5 F! ~4 ]4 W - TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
' U6 w, ]; i4 ? - }7 p! u* O& N9 U% s3 M
- catch (SocketException ex)
9 a8 f. ~* R' L: e2 P; U0 q# W - { Y b0 @! t5 g& g" a
- this.result = null;
, y# Z3 C) `; R( n0 F6 y - this.socket.Close();
3 t& @# w& ]7 a( q; M( S. R' Z - Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));
& `; ?0 ?6 c8 ` B' m9 K5 Q' Q. k8 H - this.Disconnect();/ F) S7 j: [+ S* H( @; b$ L4 R3 G9 b2 B
- }: L, T( }/ \# l" s/ H
- }
复制代码 % N8 W$ g* ~8 q) M E$ p
2 h8 \4 q' `0 M1 H1 i( F& E {" v8 `" T# I; |2 |# T
- address=ip地址
6 f$ _# @; ~! Q* g' @/ n7 V - ( h/ S) U* u) \) t, T/ @. n6 ]3 N
- byte[] bytes = Encoding.Default.GetBytes(address);
" I& d, r" G ~7 \ - byte[] array = md.ComputeHash(bytes);
' ]! r6 j& [1 L - string text = string.Empty;
- i! D1 d7 d0 n2 T+ W# M/ N* i - for (int i = 0; i < array.Length; i++)4 E& |* L) {! }# a
- {
, {, Q& B+ D: D. @ - text += array.ToString("x6");
3 D/ Q) I, N* q7 j8 v; A - }
! f2 Q+ @1 R9 c" a5 ]1 U$ E - byte[] bytes2 = Encoding.Default.GetBytes(text);- |" Y3 a( Q: O
- byte[] array2 = md.ComputeHash(bytes2);3 k0 w, i( a6 j/ L9 |
- string text2 = string.Empty;
0 C2 T, y! t: {; P/ O9 Q - for (int j = 0; j < array2.Length; j++)
: N7 x5 D9 O3 f: c- _& g, { - {
0 u& G, I$ N, c! B, L4 u - text2 += array2[j].ToString("x2");. ]( c: S5 g7 B. N3 g
- }% a9 I% O _) j! O
- text2就是最终密文
复制代码
" H0 {1 n; I8 R2 H3 L! _( ~7 D N5 d9 R3 r& i
|
|