muddesigner/MudDesigner/Client.cs
Scionwest_cp f446c754fb Mud Designer UI:
- Began support work on the networking side of the designer UI. Attempts to connect to the server or run stand-alone.
 - Began implementing object creation.

Mud Engine:
 - Added the [Browsable(false)]  attribute to several Game properties so they are not visible within the new Designer.
2010-11-07 09:05:54 -08:00

96 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace MudDesigner
{
public class Client
{
public Client()
{
}
~Client()
{
}
public Boolean Initialize(string i, int p)
{
try
{
if (i.Length <= 0)
return false;
ip = i;
if (p <= 0)
return false;
port = p;
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
catch (Exception)
{
return false;
}
return true;
}
public Boolean Connect()
{
try
{
sock.Connect(ip, port);
}
catch (Exception)
{
return false;
}
return true;
}
public Boolean Send(string data,Boolean newLine)
{
try
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
if(newLine)
data += "\n";
sock.Send(encoding.GetBytes(data));
}
catch (Exception)
{
return false;
}
return true;
}
public Boolean Receive(out string rs,int size)
{
try
{
byte[] data = new byte[size];
sock.Receive(data);
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
rs = enc.GetString(data.ToArray());
}
catch (Exception)
{
rs = "";
return false;
}
return true;
}
public Boolean End()
{
try
{
sock.Close();
}
catch (Exception)
{
return false;
}
return true;
}
private string ip;
private int port;
private Socket sock;
}
}