MORE c# help. LALs.

Far

tsniffer
Staff member
Developer
May 19, 2003
20,180
30
2,783
540
iv gotten prity far on my client. last bit to do is to change the parameter of a users location through an argument. but im stumped.

look at my code and see if you can help...

[delphi]
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication1
{

public class Whois
{
static void Main(String[] args)
{
string strHost;

FileStream aFile = new FileStream("config.ini", FileMode.Open);
StreamReader sa = new StreamReader(aFile);
strHost = sa.ReadLine();

TcpClient client = new TcpClient();
//client = new N.Sockets.TcpClient();
client.Connect("whois.net.dcs.hull.ac.uk", 43);
StreamWriter sw = new StreamWriter(client.GetStream());
StreamReader sr = new StreamReader(client.GetStream());

try
{
sw.WriteLine(args[0]);
sw.Flush();
}
catch
{
Console.WriteLine("ERROR: No User Specified");
}
if (args.Length == 2)
{
try
{
sw.WriteLine(args[1]);
sw.Flush();
}
catch
{
Console.WriteLine("ERROR: No Location or user Specified");
}
//CHANGE LOCATION HERE

Console.WriteLine("Number of command line parameters = {0}", args.Length);
Console.Read();
}
else
{
//VIEW LOCATION HERE

// sw.Write(args[0] + args[1]);
// Console.WriteLine(sr.ReadToEnd());
Console.WriteLine(args[0] + " is in " + sr.ReadLine());
Console.WriteLine("Number of command line parameters = {0}", args.Length);
sw.WriteLine();
Console.Read();
}
}
}
}
[/delphi]

i think im almost there. its just a few lines in "//CHANGE LOCATION HERE" that i need to add to change it.

basically. in command prompt i type..


client.exe user01

and it returns "user01 is in the toilet"

or i can type

client.exe user01 "is in a shop"

which changes the location, so next time you type "client.exe user01" it returns "user01 is in a shop".

helphelphelphelp
 
Last edited:

DeathWish

LOMCN VIP
VIP
Oct 29, 2003
1,269
1
185
didnt sw.writeline work?

ya cn try closing the stream afta, sw.close

n i dnt actually get it? i tried telneting whois.net.dcs.hull.ac.uk port 43 n cudnt connect
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,180
30
2,783
540
yeah unfortunately that address blocks anything another than the hull uni computers. so testing outside uni is prity impossible.

i tried sw.write(arg[1]) and also sw.write("dfsfdsfd") and neither changed the value, so im not sure what im doing wrong.

i thought it might b to do with closing the stream to save it. but when i put sw.close(); i get crazy errors.

i should b able to get the answer tomorow in my labs, but id rather not ask them so i look smarter :P
 

DeathWish

LOMCN VIP
VIP
Oct 29, 2003
1,269
1
185
oh right thts gay thn lol erm... ya r trying to write thing while ur at uni ent ya?

wht crazy errors was ya gettin? lol
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,180
30
2,783
540
k iv got my client working properly.

[delphi]
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication1
{
public class Whereis
{
static void Main(String[] args)
{
string strHost;

try
{
FileStream aFile = new FileStream("config.ini", FileMode.Open);
StreamReader sa = new StreamReader(aFile);
strHost = sa.ReadLine();

try
{
TcpClient client = new TcpClient();
client.Connect(strHost, 43);
StreamWriter sw = new StreamWriter(client.GetStream());
StreamReader sr = new StreamReader(client.GetStream());

if (args.Length == 1)
{
sw.WriteLine(args[0]);
sw.Flush();

//View location here
Console.WriteLine(args[0] + " is in " + sr.ReadLine());
Console.WriteLine("Number of command line parameters = {0}", args.Length);
Console.Read();
}

else if (args.Length == 2)
{
//Change location here
sw.WriteLine(args[0] + " " + args[1]);
sw.Flush();
Console.WriteLine("Number of command line parameters = {0}", args.Length);
Console.WriteLine("Location Changed: " + sr.ReadLine());
Console.Read();
}

Console.WriteLine("ERROR: No User Specified.");
Console.Read();
}
catch
{
Console.WriteLine("ERROR: No such host found.");
Console.Read();
}
}
catch
{
Console.WriteLine("ERROR: Config.ini not found.");
Console.Read();
}
}
}
}
[/delphi]

you were right df, was just sw.write, my problem was the first 'try', putting that in made it skip the rest of the program.

now to do the server. :(
 

DeathWish

LOMCN VIP
VIP
Oct 29, 2003
1,269
1
185
haha lol it shouldn't be too hard, i dont think :P


p.s wtttttttttf i get banned for lol, i cnt check my pms cuz inbox is full since when was u only allowed 100