|
Hi All!!
a Class Library project contains
namespace MyCustomMethods{<br />
public class Vlidations{<br />
}<br />
}
a Cusotm Control Library uses some methods from the above project
namespace MyCustomControls{<br />
public class SSTextBox : TextBox{<br />
}<br />
}
problem is that when i create control at run time, it works fine but when i drag it on form from toolbox it just shows wait cursor and nothing happens
sorry for my bad English.
|
|
|
|
|
Hi There !
I am trying to build a server - client application, using tcp/ip and sockets.
I would like that the server will be able to listen to some clients, and if a new client "shows up", the server notice the new client and will add it to other clients.
Can someone show me an example for something like this ?
Thanks.
|
|
|
|
|
Your server socket must use the Accept method to handle incoming client requests. Actually you should use BeginAccept uses the thread pool) for server apps for performance.
In accepting these requests a handler handles the request and it is in this handler that you can add all incoming requests to wherever you want.
|
|
|
|
|
My server socket already uses Accept method.
The thing is that I eant to avoid this situation:
IPEndPoint a_EndPoint = new IPEndPoint(ipAddress, a_port);
IPEndPoint b_EndPoint = new IPEndPoint(ipAddress, b_port);
...
// Create a TCP/IP socket.
Socket a_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
Socket b_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
// Bind the socket to the local endpoint and listen for incoming connections.
try
{
a_listener.Bind(a_EndPoint);
a_listener.Listen(num_of_clients);
// The maximum length of the queue of pending connections
b_listener.Bind(b_EndPoint);
b_listener.Listen(num_of_clients);
// The maximum length of the queue of pending connections
...
while (true)
{
// Set the event to nonsignaled state.
all_done.Reset();
// Start an asynchronous socket to listen for connections.
Console.WriteLine("Waiting for a connection...");
a_listener.BeginAccept( new AsyncCallback(accept_callback_a), a_listener );
b_listener.BeginAccept( new AsyncCallback(accept_callback_b), b_listener );
...
// Wait until a connection is made before continuing.
all_done.WaitOne();
You see, I have to create a new object for socket, and to create each one its own function and its own delegat...
How can I avoid this ?
Thanks.
|
|
|
|
|
I'm noy quite sure what you mean exactly? Are you saying that an accept is required for every client? If so, and if I'm understanding exactly your situation, this is not correct.
You only need one server socket and it will be "accepting" ALL client requests. Again, all clients will be making a request to the one server listening socket. Now when the server "accepts" the a request you can process that one request as you see fit while at the same time the server may be "accepting" other requests.
All these things happen concurrently. That is why we call the server an asynchronous socket.
|
|
|
|
|
Hi and thanks for you help !
I know that I can recieve the information through one socket.
But, I need my server to distinguish between the various clients. I want to know who send a message to the server.
In adition, I want to be able to send a message to a specific client - not to all of them together !
|
|
|
|
|
Hi,
In adition, I want to be able to send a message to a specific client - not to all of them together !
When you "accept" a request, you then get the socket, whereby this socket responds solely to the requesting client and no other.
But, I need my server to distinguish between the various clients. I want to know who send a message to the server.
The client will have to pass some identification from itself to the server within the buffer that it sends. The server can then identify the client.
Cheers
|
|
|
|
|
Hi again !
YOu wrote: "When you "accept" a request, you then get the socket, whereby this socket responds solely to the requesting client and no other."
But, I want to send data to some of my clients:
1. I don't want to reply - I want to send something to a certain client without the need to recieve something from him right now.
2. I want to be able to send the message to some client - for example, to send data to clietn_ID: 1, 3, 5.
How can I do this ?
|
|
|
|
|
I'd like to be able to determine if the keyboard has "Num Lock" enabled or disabled from C#, as well as to set this state programmatically from C#.
I've found some info on how to do this in Win32 in C using "GetKeyboardState" and "keybd_event", but I'm not sure how to call this from C# or if there is a more direct approach in C#.
|
|
|
|
|
Here is some code, uses Win32 interop
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
public enum SpecialKey
{
CapsLock = 0x14,
NumLock = 0x90,
ScrollLock = 0x91
}
public class SpecialKeyState
{
[DllImport("User32.dll")]
private static extern short GetKeyState(int nVirtKey);
public static bool GetSpecialKeyState( SpecialKey k )
{
int s;
s = GetKeyState((int)k);
s &= 0x01;
if (s == 1)
return true;
else
return false;
}
}
I didn't test this code exactly. It is ripped from a component I made from some other code on the internet. I modified it to let you test any of the speical keys (my version allows you to set a member and then test that key on an interval).
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thanks Nathan! That does the trick for getting the num lock state.
I'm trying to figure out how to set the num lock now. I found a Win32 example that does this using keybd_event:
keybd_event(VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0);
The signature of this method is:
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // function options
ULONG_PTR dwExtraInfo // additional keystroke data
);
I wasn't exactly sure what types to use for the last two parameters in the extern statement, so I tried "long" and crossed my fingers:
[DllImport("User32.dll")]
private static extern void keybd_event(byte bVk,
byte bScan,
long dwflags,
long dwExtraInfo);
This actually works the first time I call it, but it gets really flaky after that. I figure that I'm not using the right types for the last two parameters, so I'm stomping on memory somehow. Any clue what types I should use?
Thanks again.
|
|
|
|
|
I also tried unsafe code with a long pointer, but this doesn't work any better than just using longs:
[DllImport("User32.dll")]
private unsafe static extern void keybd_event(byte bVk,
byte bScan,
uint dwflags,
ulong* dwExtraInfo);
|
|
|
|
|
Try using IntPtr instead of the long for the ULONG_PTR.
I really don't know, perhaps one the people with more experience in Interop will be able to tell us.
Later,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I have a picturebox in my application and I have alist of images too.When user choose each image it display in that picture box.My problem is when size of image bigger than size of picture box,part of image does not shown in picturebox.The question is how can I manage this size when the image bigger than picturebox and show all of it in that picture box?Any suggestion or idea?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
You can do a couple different things with the SizeMode property of the PictureBox.
If you set it to PictureBoxSizeMode.StretchImage then the image will change it's size to match the picturebox. Not my favorite way of doing it, but if you must be able to view all of the image at one time then this can work (to make it look better you may have to resize the picture box a little so that the aspect ratio of the image is retained).
My favorite method is to place the picture box in a panel, set the SizeMode to PictureBoxSizeMode.AutoSize which will change the size of the picture box to match the image. Now set the panel's AutoScroll property to true. Now you will get scrollbars which can be used to view the hidden parts of the image, and the image will display at normal size.
Without knowing your exact requirements that is all I can offer, but it covers the two scenarios I can think of.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks James.Both of them are what I need.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi all,
Does anyone know why this will throw an exception when the address reaches 10.20.30.128?
Any Ideas?
Thanks
string from = "10.20.30.0";<br />
IPAddress ipAFrom = IPAddress.Parse(from);<br />
IPAddress tempIP;<br />
for(int i=0; i <255; i++)<br />
{<br />
tempIP = new IPAddress( IPAddress.NetworkToHostOrder(IPAddress.HostToNetworkOrder((int)ipAFrom.Address)+i));<br />
addToIPTable(tempIP.ToString());<br />
} <br />
|
|
|
|
|
Looks like a bug in the IPAddress class. The NetworkToHostOrder creates a negative int , which causes the constructor to throw an exception.
Try this:
tempIP = new IPAddress(
(uint)IPAddress.NetworkToHostOrder(
IPAddress.HostToNetworkOrder((int)ipAFrom.Address) + i));
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi,
Is there a tutorial around for making skinned apps like winamp in C#? (I mean how can i make good looking and different UI s?)
Thanx...
|
|
|
|
|
In C# resource editor let say I am putting a label string say "Hello Label".
Resource editor generate the code for it in InitializeComponent() like
this.lblMessage.Text = "Hello Label";
I am coding for multiple languages (German/French). So it create lot of
problem for me. I have to change all these lines to
this.lblMessage.Text = resManager.GetString("txtHello");
I am storing all these messages in a MyApp.resx files and maintaining a
separate .resx file for each language like for German there is a
MyApp.de.resx and setting the UICulture in my code.
Is there any simpler way for this?
Sonork ID 100:25668
|
|
|
|
|
I think you can do the same thing using the properties editor. First set the Localizable property on the form to true, then set the form's Language property to the first language. Now proceed to set all of the properties that need localized strings. Then change the Language property to the next language, and change all of the localized strings, repeat.
I did this while playing around a couple months ago and it seemed to produce what you want.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thank you James
Sonork ID 100:25668
|
|
|
|
|
Hi all,
How can I fix the TextBox height permanently? If we change the font size, the height of the TextBox changes accordingly. But in the OpenFontDialog , we have a TextBox [which displays the sample/preview], for which the height remains permanent, even when the font size is high. How can we do this ?
Thanks
Smitha
It is better to be hated for what you are than to be loved for what you are not.
-- Andre Gide
|
|
|
|
|
Smitha Vijayan wrote:
How can we do this ?
I think you are looking for the AutoSize property.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks James
Smitha
It is better to be hated for what you are than to be loved for what you are not.
-- Andre Gide
|
|
|
|