Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hex
ygopro2
Commits
eea918a9
Commit
eea918a9
authored
Jul 06, 2025
by
hex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized TcpHelper.cs
parent
d2b594a5
Pipeline
#38589
failed
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
104 deletions
+98
-104
Assets/SibylSystem/MonoHelpers/TcpHelper.cs
Assets/SibylSystem/MonoHelpers/TcpHelper.cs
+98
-104
No files found.
Assets/SibylSystem/MonoHelpers/TcpHelper.cs
View file @
eea918a9
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Collections.Concurrent
;
using
System.IO
;
using
System.IO
;
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Text
;
using
System.Text
;
...
@@ -12,10 +13,13 @@ public static class TcpHelper
...
@@ -12,10 +13,13 @@ public static class TcpHelper
{
{
public
static
TcpClient
tcpClient
=
null
;
public
static
TcpClient
tcpClient
=
null
;
static
NetworkStream
networkStream
=
null
;
private
static
NetworkStream
networkStream
=
null
;
private
static
bool
canjoin
=
true
;
private
static
bool
roomListChecking
=
false
;
static
bool
canjoin
=
true
;
public
static
bool
onDisConnected
=
false
;
static
bool
roomListChecking
=
false
;
private
static
ConcurrentQueue
<
byte
[
]>
datas
=
new
ConcurrentQueue
<
byte
[
]>
();
public
static
void
join
(
public
static
void
join
(
string
ipString
,
string
ipString
,
...
@@ -89,33 +93,26 @@ public static class TcpHelper
...
@@ -89,33 +93,26 @@ public static class TcpHelper
public
static
void
addDateJumoLine
(
byte
[]
data
)
public
static
void
addDateJumoLine
(
byte
[]
data
)
{
{
Monitor
.
Enter
(
datas
);
// 不再需要手动加锁 Monitor.Enter/Exit
// ConcurrentQueue.Enqueue 本身就是线程安全的。
try
try
{
{
datas
.
Add
(
data
);
datas
.
Enqueue
(
data
);
}
}
catch
(
System
.
Exception
e
)
catch
(
System
.
Exception
e
)
{
{
// 保留异常处理逻辑
UnityEngine
.
Debug
.
Log
(
e
);
UnityEngine
.
Debug
.
Log
(
e
);
}
}
Monitor
.
Exit
(
datas
);
}
}
public
static
bool
onDisConnected
=
false
;
static
List
<
byte
[
]>
datas
=
new
List
<
byte
[
]>
();
public
static
void
preFrameFunction
()
public
static
void
preFrameFunction
()
{
{
if
(
datas
.
Count
>
0
)
{
while
(
datas
.
TryDequeue
(
out
byte
[]
data
))
if
(
Monitor
.
TryEnter
(
datas
))
{
for
(
int
i
=
0
;
i
<
datas
.
Count
;
i
++)
{
{
try
try
{
{
MemoryStream
memoryStream
=
new
MemoryStream
(
datas
[
i
]
);
MemoryStream
memoryStream
=
new
MemoryStream
(
data
);
BinaryReader
r
=
new
BinaryReader
(
memoryStream
);
BinaryReader
r
=
new
BinaryReader
(
memoryStream
);
var
ms
=
(
StocMessage
)(
r
.
ReadByte
());
var
ms
=
(
StocMessage
)(
r
.
ReadByte
());
switch
(
ms
)
switch
(
ms
)
...
@@ -202,10 +199,7 @@ public static class TcpHelper
...
@@ -202,10 +199,7 @@ public static class TcpHelper
// Program.DEBUGLOG(e);
// Program.DEBUGLOG(e);
}
}
}
}
datas
.
Clear
();
Monitor
.
Exit
(
datas
);
}
}
if
(
onDisConnected
==
true
)
if
(
onDisConnected
==
true
)
{
{
onDisConnected
=
false
;
onDisConnected
=
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment