Skip to content

Commit fafa0b3

Browse files
author
“寧々”
committed
1.08 BugFix
1 parent e9b4b38 commit fafa0b3

File tree

8 files changed

+37
-12
lines changed

8 files changed

+37
-12
lines changed

ReservoirServer/AMQCommunicator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Initialization()
3333
{
3434
Dispose();
3535
_sender = new SimpleQueueSender(queue_name, uri);
36-
_subscriber = new SimpleTopicSubscriber(topic_name, uri, "xxx", "zzz", null);
36+
_subscriber = new SimpleTopicSubscriber(topic_name, uri, "client_"+ platform_id, "consumer_"+ platform_id, null);
3737
_subscriber.OnMessageReceived += _subscriber_OnMessageReceived;
3838
}
3939

ReservoirServer/Driver/BoxTCPDriver.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ public Task SendDataAsync(IComClient client, byte[] data)
1414
BoxTCPClient carclient = client as BoxTCPClient;
1515
NetworkStream ns = carclient.Client.GetStream();
1616
ns.WriteTimeout = TransmitTimeout;
17-
var task = ns.WriteAsync(data, 0, data.Length);
17+
Task task = null;
18+
try
19+
{
20+
task = ns.WriteAsync(data, 0, data.Length);
21+
}
22+
catch(System.IO.IOException)
23+
{
24+
client.Disconnected();
25+
}
26+
catch(SocketException)
27+
{
28+
client.Disconnected();
29+
}
30+
1831
return task;
1932
//task.ContinueWith((t) => { this.OnComDataSent?.Invoke(client, data.Length); });
2033

ReservoirServer/Driver/IComClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void Disconnect()
5656
{
5757
Client.Close();
5858
IsAlive = false;
59+
OnDisconnected?.Invoke();
5960
}
6061

6162
public void Disconnected()

ReservoirServer/Driver/SimpleAMQSamples.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public SimpleTopicSubscriber(string topicName, string brokerUri, string clientId
8989
public void OnMessage(IMessage message)
9090
{
9191
ITextMessage textMessage = message as ITextMessage;
92+
//Console.WriteLine(textMessage);
9293
if (this.OnMessageReceived != null)
9394
{
9495
this.OnMessageReceived(textMessage.Text);

ReservoirServer/Driver/TCPDriver.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected virtual void HandleAsyncConnection(IAsyncResult res)
104104
client.ReceiveTimeout = TransmitTimeout;
105105
byte[] buff = new byte[client.ReceiveBufferSize];
106106
client.GetStream().ReadTimeout = TransmitTimeout;
107-
BoxTCPClient carclient = new BoxTCPClient(client);
107+
BoxTCPClient carclient = new BoxTCPClient(client) { IsAlive = true };
108108
RecState state = new RecState { Client = carclient, Buffer = buff };
109109
this.OnComClientConnected?.Invoke(carclient);
110110
state.Stream.BeginRead(state.Buffer, 0, state.Buffer.Length, HandleClientAsyncRec, state);
@@ -118,16 +118,18 @@ protected virtual void HandleClientAsyncRec(IAsyncResult res)
118118
return;
119119
RecState state = (RecState)res.AsyncState;
120120
TcpClient client = state.Client.Client;
121-
byte[] oldbuff = state.Buffer;
122-
NetworkStream ns = state.Stream;
123121
if (client == null)
124122
return;
125-
if(client.Connected == false)
123+
124+
byte[] oldbuff = state.Buffer;
125+
126+
if(client.Connected == false )
126127
{
127128
this.OnComClientDisconneted?.Invoke(state.Client);
128129
state.Client.Disconnected();
130+
return;
129131
}
130-
132+
NetworkStream ns = state.Stream;
131133

132134
int b2r = 0;
133135
try
@@ -139,6 +141,10 @@ protected virtual void HandleClientAsyncRec(IAsyncResult res)
139141
{
140142
b2r = 0;
141143
}
144+
catch(SocketException)
145+
{
146+
b2r = 0;
147+
}
142148
catch(ObjectDisposedException)
143149
{
144150
return;
@@ -160,7 +166,8 @@ protected virtual void HandleClientAsyncRec(IAsyncResult res)
160166

161167
else
162168
{
163-
if(AsyncRecBuffer)
169+
state.Client.IsAlive = true;
170+
if (AsyncRecBuffer)
164171
{
165172
byte[] buffer = new byte[b2r];
166173
Buffer.BlockCopy(state.Buffer, 0, buffer, 0, b2r);

ReservoirServer/Enterty/Box.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public Box(string id,IComClient client)
3535
{
3636
comClient.OnDisconnected += () =>
3737
{
38-
locker.EnterWriteLock();
38+
//locker.EnterWriteLock();
3939
State = BoxState.Offline;
40-
locker.ExitWriteLock();
40+
//locker.ExitWriteLock();
4141
};
4242
}
4343
}

ReservoirServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ReservoirServer
1616
class Program
1717
{
1818
//TODO: Log file, Safety(Encryption), JSON error catch, system service
19-
public static readonly string version = "1.07";
19+
public static readonly string version = "1.08";
2020

2121
#if DEBUG
2222
public static string VERSION => version + "a";

ReservoirServer/SimpleBoxAdapter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,15 @@ public void SimpleBoxDataSubscribeHandler(string json)
105105
Box box = _list[bid];
106106
if (box != null)
107107
{
108+
bool online = false;
108109
boxdata.DeviceN = bid;
109110
string senddata = JsonConvert.SerializeObject(boxdata, jsonSettings);
110111
box.locker.EnterReadLock();
111112
var client = box.ComClient;
113+
online = (box.State == BoxState.Online);
112114
box.locker.ExitReadLock();
113-
_server.SendPack(client, senddata);
115+
if(online)
116+
_server.SendPack(client, senddata);
114117
}
115118
}
116119
}

0 commit comments

Comments
 (0)