Explorar el Código

Added checks for tcp connection and modified interface class name

tags/3.0.0
Teknikode hace 5 años
padre
commit
d6e2cc1529
Se han modificado 4 ficheros con 25 adiciones y 5 borrados
  1. 1
    1
      Combot.csproj
  2. 18
    1
      IRCService.cs
  3. 1
    1
      Methods.cs
  4. 5
    2
      TCP/TCPInterface.cs

+ 1
- 1
Combot.csproj Ver fichero

@@ -40,7 +40,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="IRCService.cs" />
<Compile Include="Interface.cs" />
<Compile Include="Methods.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCP\TCPInterface.cs" />
<Compile Include="TCP\TCPTypes.cs" />

+ 18
- 1
IRCService.cs Ver fichero

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;

namespace Combot
{
@@ -15,6 +16,22 @@ namespace Combot
_tcp = new TCPInterface();
}

internal bool Connect(IPAddress IP, int port, int readTimeout, int allowedFailedCount = 0)
{
bool result = false;
if (!_tcp.Connected)
{
result = _tcp.Connect(IP, port, readTimeout, allowedFailedCount);
}

return result;
}

internal bool Disconnect()
{
bool result = false;

return result;
}
}
}

Interface.cs → Methods.cs Ver fichero

@@ -6,7 +6,7 @@ using System.Threading.Tasks;

namespace Combot
{
public class Interface
public class Methods
{
}
}

+ 5
- 2
TCP/TCPInterface.cs Ver fichero

@@ -13,6 +13,7 @@ namespace Combot
{
internal event Action<TCPError> TCPErrorEvent;
internal event Action<int> TCPConnectionEvent;
internal bool Connected = false;

private IPEndPoint _serverIP = null;
private int _readTimeout = 250;
@@ -39,6 +40,7 @@ namespace Combot
_tcpClient.ReceiveTimeout = _readTimeout;

_tcpStream = new NetworkStream(_tcpClient);
Connected = true;
return true;
}
catch
@@ -55,6 +57,7 @@ namespace Combot

internal void Disconnect()
{
Connected = false;
if (_tcpStream != null)
{
_tcpStream.Close();
@@ -67,7 +70,7 @@ namespace Combot

internal void Write(string data)
{
if (_tcpStream.CanWrite)
if (_tcpStream.CanWrite && Connected)
{
byte[] message = System.Text.Encoding.UTF8.GetBytes(data + Environment.NewLine);
_tcpStream.Write(message, 0, message.Length);
@@ -78,7 +81,7 @@ namespace Combot
{
try
{
if (_tcpStream.CanRead)
if (_tcpStream.CanRead && Connected)
{
byte[] readBytes = new byte[100000];
_tcpStream.Read(readBytes, 0, readBytes.Length);

Cargando…
Cancelar
Guardar