|
- public void Connect(string address, int port). t9 \) ?3 h% C) _
- {8 L7 `% x" ?, F6 t. r. }0 I
- if (this.socket.Connected)
' n; w$ k+ \ e N3 g( T2 w - {: A4 _/ _ y7 |3 B; z1 H' H
- Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));
5 N; ?0 M) T2 f4 t: X& a - return;3 r0 n/ N, `' L, g! w1 ^
- }
( |, m! h2 r8 U - this.address = address;
# K' T6 d, `2 E3 |; F - this.port = port;
4 A. h* C' b+ M9 f. P3 D - MD5 md = MD5.Create();" I; i6 j e4 u4 _0 U# a
- string a = "12546f1c61454538c45490";
9 ~& c8 i J! h6 o - string a2 = "1252051ca54456902c7054bc";
5 d' F( C) i5 l$ k, R8 P - string a3 = "66610b45455576";9 @$ i: \2 m/ T! D% X& _, D
- string a4 = "4582fdgs4545wr42saf1";
# S1 l" y( ^8 I0 l - byte[] bytes = Encoding.Default.GetBytes(address);. e9 ~* J: j5 \3 l. c3 Y
- byte[] array = md.ComputeHash(bytes);9 | U' _/ O. I
- string text = string.Empty;" j k% |/ ~! E3 A& o
- for (int i = 0; i < array.Length; i++)
1 o+ M q! L; X+ | l" G - {
( W* _. R6 |& S2 q4 M, i" e - text += array[i].ToString("x6");8 k' ]+ Q- t" x8 Q* t9 J
- }6 S1 N' n+ }4 D3 n+ f$ D
- byte[] bytes2 = Encoding.Default.GetBytes(text);
, C% ~5 p7 O! B! d/ ~0 S - byte[] array2 = md.ComputeHash(bytes2);
, X2 f3 ~- ?6 v0 e; G# I' ? - string text2 = string.Empty;$ q7 D6 P/ i- _/ b7 o
- for (int j = 0; j < array2.Length; j++)$ R+ v; ^/ v$ g$ {0 }# a
- {- ~ `+ j. P. [" [ a) U
- text2 += array2[j].ToString("x2");
8 _; X' X/ R3 d: E; A- C - }" W% t# s: X6 I, v( E
- if (!(a == text2) && !(a2 == text2) && !(a3 == text2))2 x! S0 X% b9 I% g, n
- {9 D% l* o2 L& \% O1 ]3 ?4 Y3 t: y
- if (!(a4 == text2)), X) ^7 ` B2 ~
- {
+ ]& ]* a! c, [. M6 b$ k+ [ - this.Disconnect();
1 J8 o1 n* O* D( f' N% g - return;
* o7 s |3 _% X7 y3 o% o0 W; w2 l - }
r/ I$ t& M% ^* c& H* S- y - }
1 d# b' X( `8 R" Z - try
! C$ \& ^ U7 C: h3 g - {: w9 l, {4 {& @3 D
- Log.Debug("Socket尝试建立连接");( i' z9 d- R& D% p4 ~
- this.ConnectStatus = ConnectStatusEnum.HasConnect;+ S/ n1 I; t9 B6 }
- this.connetTime = Time.time;
( I) X( g1 V) p) @' J/ B6 U - this.result = this.socket.BeginConnect(address, port, null, null);
; N' ~/ S! P/ B1 k - TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
' e& H5 n4 \' T: N( j* B; M - }9 B* Z+ H8 H, t; l% F0 \, q
- catch (SocketException ex)
2 b$ ?+ Z0 u& q8 @$ N - {
7 u. L3 B' A/ a' c; ?8 k8 J8 ] - this.result = null;
1 u# n N# A8 O* }: V - this.socket.Close();
- a3 J3 z# R8 V2 O6 d) O, X - Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));
0 z. ^& O p+ V - this.Disconnect();5 f- s8 J; s1 D& N1 h
- }! ^+ u, h/ O3 D+ D7 O. v
- }
复制代码 . a6 S$ E# `/ e7 o
7 c6 G- s8 x Q3 z' K4 `
9 }& z; a- s* P- y& T
- address=ip地址: }7 n8 Q% |2 x" K* z
_4 L3 V; Y1 Z- byte[] bytes = Encoding.Default.GetBytes(address);0 l7 s# r7 M9 y$ m
- byte[] array = md.ComputeHash(bytes);- m* N( j5 B4 y1 y
- string text = string.Empty;1 ?2 E+ V9 v& e+ \9 _# D& w
- for (int i = 0; i < array.Length; i++); r' ~6 I6 W/ G% U- W
- {, b: d1 f A. F/ t3 B
- text += array.ToString("x6");
! U w1 o9 R( P4 ] - }
9 h. D p6 _0 ^2 {# h - byte[] bytes2 = Encoding.Default.GetBytes(text);: P/ s* R6 J+ L) R2 L7 I' \9 y
- byte[] array2 = md.ComputeHash(bytes2);
! P# b! H. }! |: Y0 G! |' d5 D - string text2 = string.Empty;9 @4 W4 c0 i( S) ], {' M* r
- for (int j = 0; j < array2.Length; j++). Q4 {" q7 M+ \: A+ A8 s; K8 g# l
- {
2 w1 }" l! [6 p: [4 t! X - text2 += array2[j].ToString("x2");
6 e% \$ ?7 x6 C - }
% m* S i- `) n - text2就是最终密文
复制代码
! T! u3 a9 N+ E$ w& F
/ \, C7 w, }, I |
|