Skip to content

Commit

Permalink
fix(lib): network exception
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojiuwo1993 committed Nov 3, 2023
1 parent 8887cf1 commit d7eb831
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@ public class HttpConnectionManager : IConnectionManager
public HttpConnectionManager(IPEndPoint endPoint)
{
Listener = new HttpListener();
Listener.Prefixes.Add($"http://localhost:{endPoint.Port}/");
string host;
if (endPoint.Address.ToString() == "0.0.0.0")
{
host = "+";
}
else if (endPoint.Address.ToString() == "127.0.0.1")
{
host = "localhost";
}
else
{
host = endPoint.Address.ToString();
}

Listener.Prefixes.Add($"http://{host}:{endPoint.Port}/");
}
public void Start()
{
Expand Down
10 changes: 5 additions & 5 deletions src/Libraries/Core/src/Network/Tcp/Server/TcpConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Linq;
using System.Net;
using System.Net.Sockets;
Expand Down Expand Up @@ -47,13 +46,14 @@ public void OnConnected()

private void StartReceiving()
{
var stream = Client.GetStream();
byte[] buffer = new byte[2048];
int bytesRead;

while (true)
{
try
{
var stream = Client.GetStream();
byte[] buffer = new byte[2048];
int bytesRead;
bytesRead = stream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
Expand All @@ -64,7 +64,7 @@ private void StartReceiving()
var receivedData = buffer.Take(bytesRead).ToArray();
OnReceive(receivedData);
}
catch (Exception ex)
catch (SocketException ex)
{
LogWriter.LogError(ex);
OnDisconnected();
Expand Down

0 comments on commit d7eb831

Please sign in to comment.