Jump to content

chat server

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
pjs

pjs

    Newbie

  • Members
  • PipPip
  • 10 posts
I have done a project in c# of chat server application using which i have made a connection with server machine using ip address and send datas to the server database but what i need is to instead of sending datas to the server machine database i want to store it in a server text file ...is it possible and i hav attached the code below

Attached Files



#2
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
Instead of the clsMaster class write a class for a stream writer. You already have at least one stream writer in your code so i'm assuming you know how this works already, so what exaclty is the issue? If you need help with Stream Writer code check out the msdn page on it or check out the tutorial section where xav has some nice examples. I was getting build errors when I compiled so I can't really give you any further help until I get it debuged, wich isn't on the top of my priority list.

#3
pjs

pjs

    Newbie

  • Members
  • PipPip
  • 10 posts
thanks for u'r reply but i have already created a class for text writer but it didn't works at all...i am working with remote desktop as my server and i need to create a text file in that server and now i am using database for storing the datas but now i need to directly store it in a text file ..can u give me u'r suggetion..

#4
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
remote desktop? This shouldn't change the process. If you are connecting to the server ok this shoudn't matter. The process for writing a text file is much simpler than that of writing the data in a db file and shouldn't be the problem. Are you sure you did everything the same as far as passing data to the writer class instead of the sql class? Can I see the class for the stream writer? Maybe I could see what went wrong from that. Or if you figure it out let me know what the holdup was. Im currious as to why a writer would give you problems when the sql solution was working already.

#5
pjs

pjs

    Newbie

  • Members
  • PipPip
  • 10 posts
ya i have given every thing but text file is not created ...do u have any ideas ...the code which i have written for text writer is as follows

using System;
using System.IO;
using System.Collections;

public class Program
{
public Program ()
{
Hashtable ht = new Hashtable();
ArrayList arr = new ArrayList();
string[] lines = File.ReadAllLines(@"d:\\test.txt");
string temp = null;

for (int i = 0; i < lines.Length; i++)
{
temp = lines[i].Substring(0, lines[i].IndexOf(','));
if (temp.ToUpper().StartsWith("BTS_ID")) continue;
if (i == 1 || arr.IndexOf(temp) == -1)
{
arr.Add(temp);
}
}

string[] pars = null;
string bts = null;
for (int i = 0; i < lines.Length; i++)
{
lines[i] = lines[i].TrimEnd();
if (lines[i] == "")
{
if (i == lines.Length - 1)
{
ht.Add(bts, pars);
}
else
{
continue;
}
}
if (lines[i].ToUpper().StartsWith("BTS_ID"))
{
if (i > 0)
{
ht.Add(bts, pars);
}
bts = lines[i].Substring(7).TrimEnd(',');
pars = new string[arr.Count];
for (int k = 0; k < arr.Count; k++)
{
pars[k] = "null";
}
}
else
{
for (int j = 0; j < arr.Count; j++)
{
if (lines[i].ToUpper().StartsWith((string)arr[j]))
{
pars[j] = (lines[i].TrimEnd().Split(','))[1];
}
}
if (i == lines.Length - 1) ht.Add(bts, pars);
}
}

// display header line

TextWriter tw = Console.Out;

using (StreamWriter sw = new StreamWriter(@":\\test.txt")) // or whatever
{
// set output to file

Console.SetOut(sw);

// write header line

Console.Write("BTS_ID ");

foreach (string title in arr)
{
Console.Write(title);
Console.Write(" ");
}

Console.WriteLine();

// write hash table
foreach (string key in ht.Keys)
{
Console.Write("{0} ", key);
pars = (string[])ht[key];
foreach (string par in pars)
{
Console.Write(par);
Console.Write(" ");
}
Console.WriteLine();
}
}

// restore console output

Console.SetOut(tw);
Console.ReadKey();
}
}

#6
pjs

pjs

    Newbie

  • Members
  • PipPip
  • 10 posts
plz do reply for my post

#7
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
There are a couple of problems with the code you posted. First thing I noticed was your code to reset the console output to standard wont work. I think it takes a couple more lines than that: Console.SetOut Method Try this link for a good example of a stream writer like the one you want (it even has a stream reader built in). You also need to use the "new" opperator for instantiating an array. You can still do it together with its declaration but you need the "new" keyword. Thats all I saw so far...Good Luck and I hope this helped

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
... and next time, use CODE tags. ;) And +rep to gaylo.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
thx xav:) Im sure it will come back around once i spread enough around to give you more.

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Thanks, but I haven't helped you or anything recently?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums