|
- public void Connect(string address, int port): g. O% `; f4 l& O8 C
- {
' U4 A0 {" n. @' l/ B8 L - if (this.socket.Connected)5 z! U/ d3 p: }. ^8 J
- {
# X9 M; ], j% m; b5 V+ l' ^0 n - Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));
2 _' F2 h7 d/ b! t7 |$ d& S. A# X - return;& |/ b. ^ e E& J: Z7 |
- }
5 O! v$ y7 z' O - this.address = address;
, L; B' B& G6 | - this.port = port;$ d/ s: D, J1 O* N* q
- MD5 md = MD5.Create();
$ J( B+ U' s6 N% d! S5 M/ r. W) ` - string a = "12546f1c61454538c45490";
8 `7 ^5 _* _0 ^0 l$ M4 r, V- \ - string a2 = "1252051ca54456902c7054bc";6 h+ x! g, o1 w9 Z
- string a3 = "66610b45455576";
; D+ A5 M+ M* d8 C. {& { - string a4 = "4582fdgs4545wr42saf1";
) c4 f9 W- ?/ D# l - byte[] bytes = Encoding.Default.GetBytes(address);
2 A( B" m3 j: e, I( g4 X - byte[] array = md.ComputeHash(bytes);
# B- N8 s8 D1 \8 ~ - string text = string.Empty;
7 F6 D) `+ r- @ - for (int i = 0; i < array.Length; i++)
" m6 _( R+ r, d: O: C7 G2 s A - {* \& l( }% [, w
- text += array[i].ToString("x6");7 U+ ?. r4 |, L& z4 b6 a, v
- }( \$ J2 d, s& D$ U) `; M
- byte[] bytes2 = Encoding.Default.GetBytes(text);8 h; L2 b! C: o1 s+ @
- byte[] array2 = md.ComputeHash(bytes2);
% \/ a5 f0 M0 Z' u& ? - string text2 = string.Empty;
' L4 x3 ~0 B+ s4 D0 \5 [) Z - for (int j = 0; j < array2.Length; j++)
& V8 i7 ]0 d! B: w- l - {! G: c+ r, `! t1 g2 r a# x
- text2 += array2[j].ToString("x2");
# A6 |( a& H% \5 q" p" Y/ p - }1 J: q, v4 @6 P& {/ I- m5 f; {$ u
- if (!(a == text2) && !(a2 == text2) && !(a3 == text2))/ B( O. Z0 f0 I8 H
- {
; f, Q. ?5 x) r: [4 d) b, U - if (!(a4 == text2))
4 Q4 B- [9 \1 E8 J; @ - {$ S$ ~% C" }# q7 R
- this.Disconnect();% D+ V2 N* W' k+ F5 R
- return;' j8 J6 R* z1 M* n5 E
- }) X# D4 K4 W( V6 [ o2 Y/ c/ X( k8 I
- }7 F. H Z% v5 j' K/ u& N" W! X
- try# P! b0 @- F, X2 w
- {
; c3 t! w: o/ E5 _2 e7 V' l4 [ - Log.Debug("Socket尝试建立连接");
6 X( w1 ]" C6 l! K - this.ConnectStatus = ConnectStatusEnum.HasConnect;1 j) ^, G2 W1 t
- this.connetTime = Time.time;
; K. ~/ ^' E0 r3 z/ G - this.result = this.socket.BeginConnect(address, port, null, null);
6 `! P1 M$ E* f! U0 v) o - TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
. S% }/ }7 ^: s. }5 s - }
, Z! z' f9 K, x0 y- p* l3 p2 \ - catch (SocketException ex); J8 G, ^2 y; m) o0 h& x
- {
( a; y. x/ T K6 X: m - this.result = null;5 s( X" V7 }* n% n" ~) C" B( e
- this.socket.Close();
- t9 Q+ S$ Z, ~, u" f5 X9 t" T) F - Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));
5 e! [0 k0 v8 l( q* C$ U - this.Disconnect();% ~3 t0 |' l7 r! e! M0 u
- }3 R; S R+ N5 }+ J B5 U3 l8 {! J
- }
复制代码 % J: m9 X. L' H) {
7 p/ e d/ t) d1 j7 a* ?$ d
; @2 U1 N2 v" y$ A% w- address=ip地址
3 F8 i+ W# `* y+ j Q- ] - / |! S9 \* x0 Z7 F7 [6 |* ]
- byte[] bytes = Encoding.Default.GetBytes(address);
" ~, ]& l p8 ~ - byte[] array = md.ComputeHash(bytes);$ B: q0 }& I# g B, k8 `
- string text = string.Empty;
) B( w0 L: m @* Q8 l - for (int i = 0; i < array.Length; i++)
) x+ H1 x$ d, b" B/ v+ g1 G - {
) Y, m4 d; h0 X$ S - text += array.ToString("x6");; x) D9 z! x- T4 b
- }9 l4 R2 r2 z/ n" M8 e
- byte[] bytes2 = Encoding.Default.GetBytes(text);- \5 [' {4 y5 H2 {+ r
- byte[] array2 = md.ComputeHash(bytes2);
2 Z! b! R; r( \0 Y+ j- q1 V - string text2 = string.Empty;
7 C; u6 K( U3 v1 O7 h - for (int j = 0; j < array2.Length; j++)0 M, _0 O5 {( Y4 x% `' v" A- J
- {
/ k% x$ T2 X' p4 A' p t8 ^ - text2 += array2[j].ToString("x2");- ~- Q4 }4 Q* [$ y6 v3 H6 D2 u) b; @
- }
$ v1 [3 X% U) g0 _ - text2就是最终密文
复制代码
/ o4 m4 }2 X& [4 Q) \9 m' Q
{/ ~( p+ X5 l1 m3 W3 P( ~& m* M* f: }/ y |
|