|
Maybe better use customised MessageBox with buttons.
|
|
|
|
|
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
@Mustufa: Sorry if you got annoyed of the earlier posts, I was confused converting C++/CLI to C# and posted the wrong code.
The code is
For server
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Collections;
using System.Text;
public static class GlobalMembers
{
public const int ECHO_PORT = 8080;
internal static void Main()
{
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 e)
{
Console.WriteLine("Exception: " + e);
}
}
}
public class ClientHandler
{
public TcpClient clientSocket;
public static Hashtable users = new Hashtable(30);
public 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);
}
}
clientSocket.Close();
}
}
I store every connected client and then send data to it, but at that time is waiting for input, that is, it is waiting for the Console::ReadLine() func.
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);
}
}
}
|
|
|
|
|
Ahmed Manzoor wrote: 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.
Client should run two threads, one for writing text to server and one for reading the text. So client will be always ready to read.
|
|
|
|
|
Well if it runs two threads, and on the write thread it is waiting for the Console::ReadLine()
At the same time the read thread prints a line, where will it be printed?
What will happen to the Console::ReadLine() func in the write thread? will it be abandoned?
|
|
|
|
|
Ahmed Manzoor wrote: What will happen to the Console::ReadLine() func in the write thread? will it be abandoned?
No. It can still read the input.
|
|
|
|
|
Ahmed Manzoor wrote: Well if it runs two threads, and on the write thread it is waiting for the Console::ReadLine()
At the same time the read thread prints a line, where will it be printed?
The problem you have here is that the standard console only has one "area" of I/O, namely the next "line" of the console. Why dont you try making your client a windows forms app, and then you can have a multiline textbox for the chat messages, and a textbox with button for the user to enter his message to send.
Or, you could open 2 console windows from your client, one to send allo messages to and one to capture user's message.
|
|
|
|
|
I have created a 16-colour 16 x 16 pixel bitmap (.bmp) file which is named the same as my custom component. The bitmap is added to the solution as an embedded resource.
In the code I have added the ToolBoxBitmap attribute prior to my component class:
[ToolboxBitmap(typeof(MultiColumnComboBox))]<br />
[Designer(typeof(MultiColumnComboBoxDesigner))]<br />
public partial class MultiColumnComboBox : ComboBox<br />
{<br />
....<br />
}
but I still get the standard 'gear' icon showing in the toolbox after compilation.
What am I doing wrong please?
|
|
|
|
|
I've never got it to work reliably unless I put the component in a seperate assembly - then it magically displays perfectly.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Apparently, Visual Studio doesn't show icons for toolbox component that are loaded automatically from project present on the solution.
If you add manually your component to the toolbox (by using 'Choose Toolbox Item' and loadin the assembly containing the control) you shound see the icon.
|
|
|
|
|
Yep, that did it! Many thanks guys.
|
|
|
|
|
From the project you always will see the gear bitmap. Try to use option from toolbox for insert items. Then it should works.
|
|
|
|
|
when i double click in a child tree node, form will be open and then the child node is disabled because neither anyone reopen the open form....
|
|
|
|
|
|
Hi all
I want to create a grid view control which inherits from grid view.
Now after i bind it datasource i want to hide some columns from gridview.
also i want to add some controls like checkbox ,dropdownlist.
How do i do this programatically.i dont want to do this using design view.
Please suggest which methods should i override and how do i create template here..
Waiting for answer
Tejesh
|
|
|
|
|
Try this:
DataGridViewCheckBoxColumn col = new DataGridViewCheckBoxColumn();
col. (fill the properties)
dataGridView1.Columns.Add(col);
|
|
|
|
|
I Google my problem but not succeed
can anybody guide me how can i write xml like following...
<parent xmlns="http://www.example.org">
<url>this is sample</url>
</parent>
How can i write the first line.
When I put it into
writer.WriteStartElement("Parent xmlns=\"http://www.example.org\"");
then it produce output like this
parent xmlns="http://www.example.org">
/parent xmlns="http://www.example.org">
/pre>
How can I write the first line.....
I don't know how I will do it.
|
|
|
|
|
|
|
Try replacing your <s with <s in the post - then we'll be able to see the html you're trying to achieve!
|
|
|
|
|
|
How does this relate to C# forum?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
This is worse...
First you post a question...Vote some with 1 vote and delete your message...
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 created a custom designer for a custom component:
internal class MultiColumnComboBoxDesigner : ControlDesigner
{
protected override void PostFilterProperties(
System.Collections.IDictionary properties)
{
properties.Remove("Font");
properties.Remove("Sorted");
base.PostFilterProperties(properties);
}
}
[Designer(typeof(MultiColumnComboBoxDesigner))]
public partial class MultiColumnComboBox : ComboBox
{
.....
}
I can add/remove properties using this method. However, how can I disable (greyed out) or enable properties please?
|
|
|
|
|
Everytime i change the Assemblyinformations in Visual Studio (under Project Settings) - the "Assemblyversion" for example - and make a new Release after i do that,
the values of the Properties (in Settings.settings) are deleted and have the default-values again (not the values, the user has assigned to the properties, when he using
the program).
Example: The Property "Database-Path" hast the default"C:\\Database.mdb"
The user assigned in the program the value "C:\\Documents and Properties\\test\\Database.mdb" to the application-property.
After i change the Assemblyversion of the program and make a new release of the program, the Property "Database-Path" has the
default-value (C:\\Database.mdb) again.
Is there any way to avoid this?
Thanks for helping!
|
|
|
|
|
Check out the GetPreviousVersion and Upgrade methods on your settings.
[Edit] Found a blog[^] on this
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|