I'm trying to to write an ident server, which yesterday worked fine, but
today its not. When I run it and connect to port 113 and try and send data
as soon as I press a button it dumps the connection, and wont let me send
the whole request, ie (1 , 2). Sometimes it'll send back
System.Byte[] : USERID : UNIX : NICKNAME
No matter what I do cant cant solve it.
[csharp]
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace IRC.Identd
{
public class Identd
{
private static string username;
private const int IdentdPort = 113;
public static void Start(string UserName)
{
username = UserName;
Thread SocketThread = new Thread(new ThreadStart(Identd.Run));
SocketThread.Start();
}
private static void Run()
{
try
{
string userid = " : USER : UNIX : " + username;
IPEndPoint listenEndPoint = new IPEndPoint(IPAddress.Any,
IdentdPort);
Socket tcpServer = new Socket(listenEndPoint.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
tcpServer.Bind(listenEndPoint);
tcpServer.Listen(int.MaxValue);
// Enter the listening loop.
while (true)
{
// Perform a blocking call to accept requests.
Socket tcpClient = tcpServer.Accept();
while (true)
{
byte[] buffer = new byte[256];
tcpClient.Receive(buffer, 0, tcpClient.Available,
SocketFlags.None);
byte[] SendBack = Encoding.ASCII.GetBytes(buffer +
userid);
tcpClient.Send(SendBack);
tcpClient.Close();
}
}
}
catch { }
}
}
}
[/csharp]