|
Hello. I was wondering, Im working on a TCP Server. How would I do the follow?
1.) When a client types something in the console, and its sent to the server, how would I parse that and do like an if(data == "hello") { blah blah }. How would I be able to parse the recieved string. If someone could help me I would GREATLY appreciate it. Here is my current server:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
public class UdpSrvrSample
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 7557);
UdpClient newsock = new UdpClient(ipep);
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
data = newsock.Receive(ref sender);
Console.WriteLine("Connection received from {0}", sender.ToString());
string welcome = "OpticVPS Remote Administration";
data = Encoding.ASCII.GetBytes(welcome);
newsock.Send(data, data.Length, sender);
while (true)
{
data = newsock.Receive(ref sender);
Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));
newsock.Send(data, data.Length, sender);
}
}
}
[X] 100% HTML
[ ] 100% PHP
[ ] 100% C#
|
|
|
|
|
Seriously?
The snippet you posted shows you how to make a string from a byte array.
|
|
|
|
|
Hi all,
How can I check for past or future date. I've a DateTime value and I want to know it's either past date or a future date from the current DateTime. Can you someone help me to do this.
Thanks.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I've found the solution. Comapre method do all what I want. Thanks for looking into my question and sorry for disturbing here.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
The system is deployed on the user PC,as the usual time it runs under the user mode,once I click some menu(or button),
the system runs under the developing mode, at this moment, the programmer can redesign the system, for example,
add some buttons on the winform, and encode the code and recomplie it.
Could you please give me some suggestion or some codes for it?
Many thanks
|
|
|
|
|
Are you asking about how to write a system where the end user can redesign the UI ? If not, I have no idea what you're saying.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
|
|
|
|
|
yes, I want to it can be redesigned the UI without the VS.net envirnment.
Do you have any idea about it ?thanks!
|
|
|
|
|
You need to define your own format to create UI elements, and to define what they do, then write a program which can read that format, and one that writes it. You may use an xml document, for example. It's far from trivial. Creating UI is easy enough, especially if you limit it to a few types of elements, the question is, how do you define what the UI elements actually DO ?
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
|
|
|
|
|
Christian Graus,Thanks for your kind help,If you know some simple examples for reference,I am very grateful!
|
|
|
|
|
Have a read through the articles on Marc Clifton's blog[^] (or here in Code Project), paying particular attention to his articles on Declarative Programming.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
If your users are WPF-tolerant, then you can use the XamlReader[^] class like they did in this thread on the MSDN forums
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
|
I've searched for some component examples but I couldn't find what I want, it seems to be simple but i'm getting few issues to develop it.
What I would like to have is a custom component inherited from a textbox and also add a Label at runtime. so, everytime I drag & drop the textbox from the toolbox to the form it comes with a label, if i move the textboxcontrol or the label, they all move together.
Is it possible to do it instead of creating a usercontrol?
Thanks in advance!
|
|
|
|
|
Yeah, write the entire thing inheriting from Control instead.
Is there is a way to do it without creating your own control?? Nope.
|
|
|
|
|
I am working on a ultra light database for .NET.
I target small programs where using in memory datatable would be wasting too much memory but using SQL Express would require a too big install.
It could be for example used for example :
- by a client application that want to cache data coming from the server
- by a small programs like a little mp3 library, custom webbrowser to store bookmarks or a list of cached files.
It has a few features that might of interest:
- Very low memory footprint
- Very compact (45 Kb so far)
- Very fast (having no transaction support, no multi-threading support has its benefit)
- Automatic caching mechanism
- Work with garbage collector
- Supports DBF format
- Supports DBF index
There is a little demo program.
I wondered if some of you could have a look.
The program shows you a table of individuals.
The menu let you add 100 random individuals.
The index support is not really implemented well.
Once you have a few hundread you can click on the header to sort by that column, the index is created only once however, I haven't written the BTREE index deletion/update yet.
http://dbfdotnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28087[^]
|
|
|
|
|
If you want opinions, write an article about it, including the source code, of course.
People will let you know what they think.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Pascal, I agree with Henry ... in addition, you could contrast it to for example, using a .NET wrapper over SQLite
'g'
|
|
|
|
|
I agree that you should make this an article. Another idea, which I've been bouncing around in my head, is to write a B+Tree implementation since they key to a small database is the indexing (without that, writing a flat file is very easy.) Yes, a wrapper around something like SQLite is an alternative, but three times in my career I've needed a B+Tree for a temporary index during data importing. I have one half done in C++, but got bored and moved onto other projects.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
Hi all
I’m looking for some assientance on auto initialising all public fields in a class.
I have a class with about 50+ fields. When an instance of the class is created and a value is assigned to the fields, it appends to the existing static value.
MyClass obj = new MyClass();
obj.Example = “THIS_STRING”; // This would therefore return STATIC_BEGINING_OF_STRINGTHIS_STRING which is desired.
My problem is that in obj.allRecords will only contain “STATIC_BEGINING_OF_STRINGTHIS_ STRING” and not “ANOTHER_STATIC_BEGINING_OF_STRING” plus the other 50 fields as they have not been initialised to their initial default value. I dont want to do it manually in the object as the point is that they are in the list as their default value even if unchanged.
Thanks for any help.
class MyClass {
public MyClass() { }
public List<string> allRecords = new List<string>();
private string _example = "STATIC_BEGINING_OF_STRING";
public string Example
{
get { return _example; }
set
{
_example += value;
allRecords.Add(_example);
}
}
private string _recordEnd = "ANOTHER_STATIC_BEGINING_OF_STRING";
public string RecordEnd
{
get { return _recordEnd; }
set
{
_recordEnd += value;
allRecords.Add(_recordEnd);
}
}
}
|
|
|
|
|
I am not exactly sure that I understand what you mean when you say:
tig2810 wrote: I dont want to do it manually in the object
If that means that you don't want to type in the code to add each field to allRecords , then I don't know how to help you.
Otherwise you might consider a static constructor .
Also you might want to consider changing the type of allRecords . Using List<string> means that each time recordEnd is modified, a new entry will be added to allRecords , You might consider a generic Hashtable or Dictionary .
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
tig2810 wrote:
I dont want to do it manually in the object
-
If that means that you don't want to type in the code to add each field to allRecords, then I don't know how to help you.
This is my point. I want to type it in the class so it's automattically initialised in the object. I dont want to have to initialise all the fields in the object, but all the values to be already available.
|
|
|
|
|
In that case a static constructor sounds like it would fit the bill.
This is the MS documentation[^]
and
This gives a few more examples[^]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Ok great, it sounds like that's the right direction for me. I've been looking and trying it out for a while but i dont see to be able to get it to work. Would you be able to help my showing me an example for the first field?
Thanks for helping. I'm still learning.
|
|
|
|
|
1. You could initialize the properties instead of initializing the fields.
class MyClass
{
public MyClass()
{
Example = "...";
RecordEnd = "...";
}
}
2. You could use reflection in the class's constructor to grab the values of all fields. I don't know if the order of addition to allRecords matters though.
class MyClass
{
public MyClass()
{
var fields = this.GetType().GetFields(...);
foreach(var field in fields)
{
allRecords.Add(field.GetValue(this));
}
}
}
|
|
|
|