muddesigner/MudEngine/Networking/ClientSocket.cs
u8sand_cp a26280b711 - Much work on the networking
- ServerSocket done.
- ClientSocket done.
- Few fixes required:
   - Warning in ServerSocket
   - Friends possible in C#?
2010-07-19 07:09:34 -07:00

70 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
// TODO: Make ClientSocket a friend of ServerSocket so I can make sock and type private
// other, havn't thought of what else I need
namespace MudEngine.Networking
{
class ClientSocket
{
public ClientSocket()
{
type = 0;
ip = 0;
}
~ClientSocket()
{
type = 0;
ip = 0;
}
public int Send(byte[] ba,int size,SocketFlags sf)
{
try
{
sock.Send(ba, size, sf);
}
catch (Exception)
{
return -1;
}
return 1;
}
public int Receive(ref byte[] ba, int size, SocketFlags sf)
{
try
{
sock.Receive(ba, size, sf);
}
catch (Exception)
{
return -1;
}
return 1;
}
public int CleanUp()
{
try
{
sock.Disconnect(true);
sock.Close();
sock.Dispose();
ip = 0;
type = 0;
}
catch (Exception)
{
return -1;
}
return 1;
}
public ProtocolType type;
public long ip;
public Socket sock;
}
}