MudConn.java
MudConn.java · 1.8 KB
From the archive palrichclient.zip
Download the archive « Back to the archive contents
/*
Java Mud Client -- MudConn module
by Michael Barton <red@smileyface.com>
Originally written for Divine Blood, telnet://shell.tetradine.com:4000
Permission is granted to modify and distribute freely.
Credit/links are appreciated, but not necessary.
Bugs and other issues can be noted to red@smileyface.com.
*/
import java.net.*;
import java.io.*;
public class MudConn
{
String host = "";
int port = 0;
Socket sock = null;
DataOutputStream sockOut = null;
BufferedInputStream sockIn = null;
byte[] buf = new byte[1048];
int i = 0;
public MudConn(String host, int port)
{
this.host = host;
this.port = port;
}
public void connect()
{
try
{
sock = new Socket(host, port);
sockOut = new DataOutputStream(sock.getOutputStream());
sockIn = new BufferedInputStream(sock.getInputStream());
}
catch(Exception e) {}
}
public String read()
{
try
{
i = sockIn.read(buf, 0, buf.length);
if (i > -1)
return new String(buf, 0, i);
}
catch(Exception e) {}
return null;
}
public void rawSend(String str)
{
try
{
sockOut.writeBytes(str);
sockOut.flush();
}
catch(Exception e) {}
}
public void send(String str)
{
try
{
sockOut.writeBytes(str+"\n");
sockOut.flush();
}
catch(Exception e) {}
}
public void close()
{
try
{
if (sockOut != null)
{
sockOut.close();
sockOut = null;
}
if (sockIn != null)
{
sockIn.close();
sockIn = null;
}
if (sock != null)
{
sock.close();
sock = null;
}
} catch(Exception e) {}
}
}