|
- public void Connect(string address, int port)4 [+ L9 I! ^$ u
- {
3 P! u( @8 R- A3 [# s1 r - if (this.socket.Connected)
4 L7 A' v5 ^6 x8 p7 J - {
0 F2 P1 c' t+ L8 ~8 Z - Debug.Log(string.Format("错误:重复建立Socke连接,重新连接时请先断开之前的连接", new object[0]));; o, V* n' S4 V# p
- return;
+ V5 C$ D1 G9 i4 Z9 v! h2 f - }
0 L8 N; H- X( N+ A% I h5 H - this.address = address;( w! c1 p9 ]! P V' o, b2 L9 p9 w# W
- this.port = port;6 O& S- s# K2 e
- MD5 md = MD5.Create();
6 k* i# c' ]' u+ H - string a = "12546f1c61454538c45490";
' s' E/ q" {! E% k9 C - string a2 = "1252051ca54456902c7054bc";9 ~! \, @! _: } Q& M
- string a3 = "66610b45455576";) e1 U5 }5 P* l5 Z9 \& r x
- string a4 = "4582fdgs4545wr42saf1";
0 F# @; L5 \" H7 C6 O. F - byte[] bytes = Encoding.Default.GetBytes(address);
$ |3 z$ g( a, |1 |6 k8 ^ - byte[] array = md.ComputeHash(bytes);
4 ?; C) ~& t% }4 G0 U7 Q- `6 U - string text = string.Empty;
' q* g" z8 B# D - for (int i = 0; i < array.Length; i++)
& ^- J8 B8 x0 M/ w - {, H2 F9 s: p3 f
- text += array[i].ToString("x6");
" U6 }; H1 ?( m9 i - }* h, r- v1 m. I( }9 Y5 N
- byte[] bytes2 = Encoding.Default.GetBytes(text);
9 @: w& @( H5 e) N - byte[] array2 = md.ComputeHash(bytes2);8 r/ U% s. J9 q8 W2 W
- string text2 = string.Empty;
6 O- ]; Y. ]5 s3 T9 T0 W - for (int j = 0; j < array2.Length; j++)
7 }3 @! X6 I; A1 y9 u, W - {
/ X% s$ W+ i9 Q, I5 B7 C* D - text2 += array2[j].ToString("x2");: j+ C* U* R) b, T% b( |
- }
; T* E" Q& z$ F9 A. b& { - if (!(a == text2) && !(a2 == text2) && !(a3 == text2))$ }" B( S9 k3 ^+ P# \8 ^/ Z5 W
- {8 o" r% Y* S, ?/ y6 j
- if (!(a4 == text2))# G- _! J. N( ]! F! F4 ~6 j
- {
/ t0 p9 G9 R7 P1 M9 P2 K7 d0 T - this.Disconnect();
% L* U2 T/ i! ~1 @7 ?4 b - return;1 j. ]4 g+ Y/ c! S- e' O4 V) A O E
- }
4 t: |) `/ A6 D6 l+ e" f - }
; L+ X0 C; d; a4 O7 Z0 w; a& @ - try
6 G! H- C2 I/ u - {
9 h; B! L9 Y4 K) I - Log.Debug("Socket尝试建立连接");
: H6 _) D- E; P; o5 c/ C2 r* z; J - this.ConnectStatus = ConnectStatusEnum.HasConnect;
: @- X6 y/ |: C! s- S& ]* k9 R# S - this.connetTime = Time.time;
0 L5 v6 T* T% J" X - this.result = this.socket.BeginConnect(address, port, null, null);
' u- x2 h7 q0 U( {' [ - TimerManager.GetInstance().AddTimerTask(new TimerTask(500f, new Action(this.checkConnect)));
' E" \; S. ^1 g$ G* Z, q9 ], \ - }
- a6 `0 `: e" Z0 x: K H - catch (SocketException ex)" P' [! U. X( ~& c Z
- {
) V6 z; Z' J5 r - this.result = null;
7 A# U# R$ N& ^ - this.socket.Close();: H0 y. K+ e; S2 p( Y
- Debug.Log(string.Format("连接服务器{0}:{1}失败:{2}", address, port, ex.Message));& h. x! h# F7 {4 P
- this.Disconnect();
+ R3 t0 e; C2 A - }
& n# a' T3 R4 s5 [ - }
复制代码 , {2 c" @! d& K: I4 P* ]
0 p/ S1 A5 z! u) s7 x n+ |. C& D
- address=ip地址
, o; f$ M# B& p- ~# e5 l( [ - , ^ f) S6 O9 i6 g4 }: y
- byte[] bytes = Encoding.Default.GetBytes(address); s6 x4 L* o$ _$ K2 g: T8 F
- byte[] array = md.ComputeHash(bytes);
: l! f( ~1 {+ b- \# p0 I! e- J - string text = string.Empty;' K" {# V# a4 ?! t3 q
- for (int i = 0; i < array.Length; i++)1 k. }$ h/ B, p- x/ y/ Z
- {$ V" k- q2 U r& a8 h2 x9 [6 p
- text += array.ToString("x6");
% Z; o# o- }4 [ - }
; M4 D3 A- h; M8 i) H+ T% W2 K - byte[] bytes2 = Encoding.Default.GetBytes(text);' U6 R, c- @+ O# n
- byte[] array2 = md.ComputeHash(bytes2);9 g1 y% M7 D) u: c7 V" g% m M! Y6 S
- string text2 = string.Empty;9 X, l8 D/ l8 t& p, N
- for (int j = 0; j < array2.Length; j++)
$ M8 g# E. b, r6 B - {9 j6 s* k# f) ~( C; D! f i0 c2 n
- text2 += array2[j].ToString("x2");
; T/ w4 a8 e+ d9 u6 O - }) P7 b z2 ?2 n; V
- text2就是最终密文
复制代码 ( d; ]3 p) J% _" H6 I* Z6 C
6 C& R% R( S; [2 Q
|
|