473,799 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sock ets;
using System.Text;
using System.Threadin g;

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(Ide ntd.Run));
SocketThread.St art();
}

private static void Run()
{
try
{
string userid = " : USER : UNIX : " + username;

IPEndPoint listenEndPoint = new IPEndPoint(IPAd dress.Any,
IdentdPort);
Socket tcpServer = new Socket(listenEn dPoint.AddressF amily,
SocketType.Stre am, ProtocolType.Tc p);

tcpServer.Bind( listenEndPoint) ;
tcpServer.Liste n(int.MaxValue) ;

// Enter the listening loop.
while (true)
{
// Perform a blocking call to accept requests.
Socket tcpClient = tcpServer.Accep t();

while (true)
{
byte[] buffer = new byte[256];
tcpClient.Recei ve(buffer, 0, tcpClient.Avail able,
SocketFlags.Non e);

byte[] SendBack = Encoding.ASCII. GetBytes(buffer +
userid);
tcpClient.Send( SendBack);

tcpClient.Close ();
}
}
}
catch { }
}
}
}
[/csharp]
May 29 '06 #1
1 2412
Roberto Oakenfold <ro*****@oakenf olde.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.co m>
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
1226
by: malachi | last post by:
Is there an python equivalent to perl IDENT module, specifically the client functionality ? TIA
2
2971
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
4551
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 leave you wondering what to do next. Do yourself a favour and change authentication type in pg_hba.conf to
20
1974
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 ident authentication problem.
5
1300
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 about small syntactic sugar:
2
4195
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 'width' for that many characters, the appropriate way to write the text on two lines is: The quick brown fox jumps over
2
1799
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 ..php file is try to create a class of type <filenameminus the .php, so eg. for testmodule.php it tries to create a class "testmodule" and puts it into an array within the module manager called $_modules Module Manager has a dispatch_message...
0
856
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 use md5 encyption for this if possible have tried editing the pg_hba.conf file to use an indent, and have added the indent to the pg_indent.conf file. I feel I must be doing some this wrong as I can’t get it to work. Please help....!!!!! Hereis my...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10482
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10225
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.