|
I think he means "bump" a thread as in a forum post. As in bring it back to the top. As in the thing we hate and pour scorn on whoever does it.
|
|
|
|
|
Ah!
<Padawan mode on>
I'd like to see him try
<\Padawan mode on>
|
|
|
|
|
My device has 4 inputed of capture intend that my application communicates with the device,
to visualize the 4 videos and to record.
Alex(alex_xso@hotmail.com)
|
|
|
|
|
Alex_xso wrote: My device has 4 inputed of capture intend that my application communicates with the device,
to visualize the 4 videos and to record.
OK, so where is the problem?
Also, do you have drivers? API to deal with the video capture device?
|
|
|
|
|
|
I have developed a simple client/server app which echoes whatever text the clients sends to the server.
Currently, it echoes text only to one client, which has send the text, but I want it to send to all the clients connected.
The problem is that when one client writes to the server after that the client waits for receiving and as soon it has received the echo it starts writing to the server, so if some other client sends to the server, and the server echoes back to all the clients, only those will receive the message which are waiting for reading, but none are except the client which has send the message to the server.
So how to overcome this?
Btw, it is a console application, is it possible to do in it?
I guess I explained it correctly. If not, then please ask again
modified on Monday, January 26, 2009 9:59 AM
|
|
|
|
|
It sounds like you're trying to emulate a group chat/IM session.
You're going to need to register all the users who "log" on to your server and are interested in the echo. The Observer pattern is precisely what you are looking for: http://www.dofactory.com/Patterns/PatternObserver.aspx[^] and http://en.wikipedia.org/wiki/Observer_pattern[^]
After reading that you should have a clue of what you ought to do but in plain English what you're doing is that you're making a list of all the registrants and instead of echoing to one, you're broadcasting the echo to each and everyone in the list.
Post back if you need more help.
|
|
|
|
|
Well, whenever a user is connected I store its connection and username in a hashtable,
and when the server receives a message, I create a for loop and gets everyone's specific stream and then send the message to them. But at that time the clients are waiting for the input, rather than reading what the server has send. Only that client reads who have send the message to the server.
Do you want me to post the code?
Heres the code for the server
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Collections;
using System.Text;
public class ClientHandler
{
public TcpClient clientSocket;
public void RunClient()
{
StreamReader readerStream = new StreamReader(clientSocket.GetStream());
NetworkStream writerStream = clientSocket.GetStream();
string returnData = readerStream.ReadLine();
string userName = returnData;
Console.WriteLine("Welcome " + userName + " to the Server");
while (true)
{
returnData = readerStream.ReadLine();
if (returnData.IndexOf("QUIT") > −1)
{
Console.WriteLine("Bye Bye " + userName);
break;
}
Console.WriteLine(userName + ": " + returnData);
returnData += "\r\n";
byte[] dataWrite = Encoding.ASCII.GetBytes(returnData)
writerStream.Write(dataWrite,0,dataWrite.Length);
}
clientSocket.Close();
}
}
public class EchoServer
{
const int ECHO_PORT = 8080;
public static void Main(string [] arg)
{
try
{
TcpListener clientListener = new TcpListener(ECHO_PORT);
clientListener.Start();
Console.WriteLine("Waiting for connections…");
while (true)
{
TcpClient client = clientListener.AcceptTcpClient();
ClientHandler cHandler = new ClientHandler();
cHandler.clientSocket = client;
Thread clientThread = new Thread(new ThreadStart(cHandler.RunClient));
clientThread.Start();
}
clientListener.Stop();
}
catch(Exception exp)
{
Console.WriteLine("Exception: " + exp);
}
}
}
and heres the code for client
using System;
using System.Net;
using System.IO;
using System.Net.Sockets;
using System.Text;
public class EchoClient
{
const int ECHO_PORT = 8080;
public static void Main(string [] arg)
{
Console.Write("Your UserName:");
string userName = Console.ReadLine();
Console.WriteLine("-----Logged In----->");
try
{
TcpClient eClient = new TcpClient("127.0.0.1", ECHO_PORT);
StreamReader readerStream = new StreamReader(eClient.GetStream());
NetworkStream writerStream = eClient.GetStream();
string dataToSend;
dataToSend = userName;
dataToSend += "\r\n";
byte[] data = Encoding.ASCII.GetBytes(dataToSend);
writerStream.Write(data,0,data.Length);
while(true)
{
Console.Write(userName + ":");
dataToSend = Console.ReadLine();
dataToSend += "\r\n";
data = Encoding.ASCII.GetBytes(dataToSend);
writerStream.Write(data, 0, data.Length);
if (dataToSend.IndexOf("QUIT") > −1)
break;
string returnData;
returnData = readerStream.ReadLine();
Console.WriteLine("Server: " + returnData);
}
eClient.Close();
}
catch(Exception exp)
{
Console.WriteLine("Exception: " + exp);
}
}
}
|
|
|
|
|
Three things:
1. Did you read the literature I posted? It'll really help you
2. Why are you using a Hashtable?
3. cHandler.clientSocket = client; See this? You're only ever responding to one and one client at any time, and if you don't mind me saying it, you're doing a bad job of it. Read the literature, it'll show you a really good way of doing things.
|
|
|
|
|
sorry I posted the old code
heres the modified one where i send messages to all.
btw i'm going to read the article you given
while you tell me if the code is correct or not
void RunClient()
{
StreamReader readerStream = new StreamReader(clientSocket.GetStream());
NetworkStream writerStream = clientSocket.GetStream();
string returnData = readerStream.ReadLine();
string userName = returnData;
users.Add(userName, clientSocket);
Console.WriteLine("Welcome " + userName + " to the Server");
while (true)
{
returnData = readerStream.ReadLine();
String tempData = returnData.ToLower();
if (tempData.IndexOf("quit") > -1)
{
Console.WriteLine("Bye Bye " + userName);
break;
}
Console.WriteLine(userName + ": " + returnData);
returnData += "\r\n";
byte[] dataWrite = Encoding.ASCII.GetBytes(returnData);
TcpClient[] tcpClients = new TcpClient[users.Count];
users.Values.CopyTo(tcpClients, 0);
for (int i = 0; i < tcpClients.Length; i++)
{
NetworkStream tempWriteStream = tcpClients[i].GetStream();
tempWriteStream.Write(dataWrite, 0, dataWrite.Length);
tempWriteStream = null;
}
}
clientSocket.Close();
}
modified on Monday, January 26, 2009 10:43 AM
|
|
|
|
|
OK, this is in the wrong forum now.
|
|
|
|
|
no, i changed the code
|
|
|
|
|
You did, from C# to C++/CLI which makes it in the wrong forum
|
|
|
|
|
it is C#
|
|
|
|
|
I know how to "create" a Service application.
I know what to write in the main() function.
I know how to add an EventLog (or other components) to the service.
I know how to define what happens when the service starts, stops or resumes.
What I want to know is this...
I want my Windows Service to run an Indexer function.
Where do I add this code in the Service application?
|
|
|
|
|
well i suppose it depends on when you want to call the function
|
|
|
|
|
In a thread that is instantiated from the Start() method.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
hi men
how can I make validation to accept specific input
such as in my text box Only email is valid input
aaa..@dddd.com
like that
|
|
|
|
|
well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.
something like:
string text = TextBox1.Text;
string[] split = text.split('@');
if(split.length == 1)
{
if(split[1].Contains('.'))
}
|
|
|
|
|
musefan wrote: well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.
Have you ever heard of Regular Expressions?
In fact, Regular Expression validators(as the name suggest) can do this with lot ease.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I have, but I dont remember how to do off top of head so offered another solution
|
|
|
|
|
<asp:TextBox ID="tbEmail" runat="server" ValidationGroup="Register" />
<asp:RegularExpressionValidator ForeColor="Red" ValidationGroup="Register" ControlToValidate="tbEmail" ErrorMessage="Email Address is not valid." ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" EnableClientScript="true" ID="RegularExpressionValidator1" runat="server" Display="Dynamic" />
Or you could create a custom validator that will do the validation for you and set your page IsValid property to true or false depending whether valid or not.
|
|
|
|
|
abu rakan wrote: hi men
There are women on this site, too.
There's a control built in for validating text, or, as someone said, you can use regex.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I am soooooo sorry "Christian Graus" about hi men
about my problem actually i don't understand you or
may be you don't understand me!!!!
|
|
|
|
|
This is a javascript email validator. This validator can be customized to allow any domain name.
// Email Validator
function emailCheck (emailStr) {
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD. 1 means check it, 0 means don't. */
var checkTLD=1;
/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
/* The following pattern is used to check if the entered e-mail address
fits the user@domain format. It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/;
/* The following string represents the pattern for matching all special
characters. We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a
username or domainname. It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";
/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes). E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";
/* The following pattern applies for domains that are IP addresses,
rather than symbolic names. E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/* Finally, let's start trying to figure out if the supplied address is valid. */
/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
// Start by checking that only basic ASCII characters are in the strings (0-127).
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
}
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
}
}
// See if "user" is valid
if (user.match(userPat)==null) {
// user is not valid
//alert("The username doesn't seem to be valid.");
return false;
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
// this is an IP address
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
return false;
}
}
return true;
}
// Domain is symbolic name. Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
return false;
}
}
/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */
if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
// Make sure there's a host name preceding the domain.
if (len<2) {
//alert("This address is missing a hostname!");
return false;
}
// If we've gotten this far, everything's valid!
return true;
}
|
|
|
|