473,396 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Ident

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]
May 29 '06 #1
1 2394
Roberto Oakenfold <ro*****@oakenfolde.fsmail.net> wrote:
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.


Well, it would help if you didn't just ignore any exceptions which are
thrown - when you catch an exception, log it. That's likely to help to
solve the connection drops.

Now, the data it returns is broken because you're trying to add a
string to a byte array. You should decode the data you've read into a
string, then add the two strings together before re-encoding them. (In
fact at the moment you could just send the received buffer back and
then the rest, but I'm assuming that's not what you want eventually.)

Note that you should be looking at the return value of Receive *and*
you should be waiting until you've seen a complete request (i.e. parsed
to the end of it) before returning the response - you're probably
reading just the first part of the request because that much was sent
by the client program, and then sending the response and closing the
socket.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: malachi | last post by:
Is there an python equivalent to perl IDENT module, specifically the client functionality ? TIA
2
by: Sergio del Amo Caballero | last post by:
Hi, I have a structer like this: <div class="node"> <a><img /></a> <div class="child"> <a><img /></a> </div> <div class="child"> <a><img /></a>
5
by: Susemail | last post by:
Is this good advice? IDENT Authentication failed for user "postgres" This error has everything to do with the way distros set up access rights for postgres. They are way too restrictive and...
20
by: Shanta McBain | last post by:
Hi I am running Mandrake 10 and would like to get sql-ledger to access the database. I can get in to the database with a local user at the command prompt and Web Admin. sql-ledger returns...
5
by: Alexander Kozlovsky | last post by:
Hello all! I have small silly syntax suggestion (SSSS) In many cases, keys in dictionary-like objects are strings, and moreover - valid Python identifiers. Something like: foo.x = y How...
2
by: giardina | last post by:
In poetry, it's commonly accepted that if a line wraps, that line should be idented. For example, if we had a line: "The quick brown fox jumps over the lazy dog" but didn't have enough...
2
by: Tyno Gendo | last post by:
I'm writing a test "modular site". So far I have created an App class, a Module Manager class and a couple of test modules. The Manager looks in a directory called 'modules' and then for every...
0
by: thegeek5 | last post by:
I have installed postgres on a unix server (Solaris 8) and trying to configure the system so that one login to the operating system can be used for multiple logins to postgres. I would also like to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.