|
-----------------------------server code snippet2--------------------------
m_TcpChan = new TcpChannel(9999);
ChannelServices.RegisterChannel(m_TcpChan);
sets = new Interface.settings();
obj = RemotingServices.Marshal(sets,"settings");
-----------------------------server code snippet2--------------------------
client connects with:
sets = (Interface.Server.IServer)Activator.GetObject(typeof(Interface.Server.IServer),"tcp://localhost:9999/settings");
With the socket connection i'm able to send single string commands, and the client can pass his IP for identifiy it later.
Do I need an extra tcp channel for my purposes?
Knack
|
|
|
|
|
I think you can use the same/existing channel.
Gary
While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'
- Dilbert
|
|
|
|
|
I tried just to marshal my object without creating a tcp channel, merely with my existing socket connection, it doesn't work ...
|
|
|
|
|
Gary Thom wrote:
When the client 'connects' by creating the remoting object .Net takes care of the TCP part. The object is created in the server and a proxy is created for the client, the client uses the object as if it were created locally.
If I understood correct: I have to create a tcp channel next to my socket connection.
That still works fine...
I added a remote method to the hosted remote class of the server, so when I call myRemoteClass.Method()(on the client)
the method on the server is executed, but I want to do it in both directions, i.e. the server can call methods on the clients, too.
So I tried to marshal a class on the client(while a class is marshaled on the server) with the existing tcp channel, but it doesn't work, how to do it?
|
|
|
|
|
I'm not sure what to tell you.
Check out the websites I posted before, and try with a simple client and server to start with.
I will try to see if I can find any information that can help you.
Gary
While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'
- Dilbert
|
|
|
|
|
Hi,
I am trying to pass multiple sections of one big byte[] into a function that takes byte[] as a parameter.
This is what I am trying to do:
method( bigBuffer[ bufferIndex ], bufferSize )
where method is declared as
void method( byte[], int )
The code above results in a compilation error because a byte cannot be converted into a byte[]. Is there a way to do this without forcing me to break the bigBuffer down into smaller byte[] byte by byte?
Thanks!
|
|
|
|
|
SebbaP wrote:
I am trying to pass multiple sections of one big byte[] into a function that takes byte[] as a parameter.
First change the signature of the method you want to call in something like this...
void Foo(byte[] byteArray, int offset, int length)
...where offset is the starting index and length the number of bytes to process. You can then call it like this:
Foo(bigBuffer, offset, length);
If you can't (or don't want to) change the function that is going to process the sections of your array you might use the static method Array.Copy [^]. However (as the name implies) it copies (a part) of the array and therefore is slower and the callee will not be able to manipulate the original data.
Best regards
Dennis
|
|
|
|
|
Thank you Dennis!
I cannot (or rather, would not like to) change the method signature, and as you mentioned, copying each element is slow. But that is what I have settled for (I would end up copying each element in the partitioned byte[] anyway inside Foo), until I - or someone else for that matter - comes up with a quicker solution.
Anyone?
Thanks!
|
|
|
|
|
SebbaP wrote:
I cannot (or rather, would not like to) change the method signature, and as you mentioned, copying each element is slow. But that is what I have settled for (I would end up copying each element in the partitioned byte[] anyway inside Foo), until I - or someone else for that matter - comes up with a quicker solution.
Copying is slower but that does not necessarily mean that it's too slow for you. Although I'd still suggest that you should consider refactoring the method you want to call, you should give Array.Copy() a try. Somehow I doubt that it copies each element. I would rather expect a simple memcopy which should not get you into trouble unless you want to copy a few gigabytes per second. If you take a look at how Array.Copy() works you'll find out that it is implemented directly in the CLR. The method is overloaded however it always results in a call of the following method:
[MethodImpl(MethodImplOptions.InternalCall),
ReliabilityContract(Consistency.MayCorruptInstance, CER.MayFail)]
internal static extern void Copy(Array sourceArray, int sourceIndex,
Array destinationArray, int destinationIndex,
int length, bool reliable);
Best regards
Dennis
|
|
|
|
|
|
Hi,
Purpose: I want to store any web page as html file.
Solution: Call GetResponse to the specified web site and download it.
Code:
public void Download( string url)
{
// Get the URI from the command line.
Uri httpSite = new Uri(url);
// Create the request object.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(httpSite);
req.ContentType = "text/html";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322)";
req.KeepAlive = false;
req.ProtocolVersion=HttpVersion.Version11;
req.Method = "GET";
req.AllowAutoRedirect=true;
req.MaximumAutomaticRedirections=100;
req.Timeout=(int) new TimeSpan(0,0,60).TotalMilliseconds;
req.Credentials = CredentialCache.DefaultCredentials;
Stream ResponseStream = null;
HttpWebResponse resp = null;
// Call EndGetResponse, which produces the WebResponse object
// that came from the request issued above.
try
{
resp = (HttpWebResponse)req.GetResponse();
// Find the data size from the headers.
string strContentLength = resp.Headers["Content-Length"];
// Read the content here...
// .....
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
if (ResponseStream != null)
ResponseStream.Close();
}
}
The above function works fine on some websites, but on some website where lots of redirection exists it throws 401 error.
Can somebody throw some light on what might be the root cause of this? I tried many options e.g. setting the authorization code as a part of header etc.
Also if you set Autoredirection propertyl of webrequest to false then it dosen't throw any error but the content returned is empty (0 length).
Thanks,
Anand
|
|
|
|
|
hello,am a new user to C# sharp. when i use a datetimepicker ( format set to short), along with some more controls in a form, the first time i executed the project, Iam able to get the focus in the Datetimepicker control(by pressing tab).
But if u select a new value in the control and use tab again am not getting the focus in datetime control. IS THIS A PATCH IN DATETIME CONTROL?
But when u click on it , the mousedown event makes the selection. so, iam thinking of invoking the mousedown evnet in the Enter Event(when the control is active by pressing tab). But not sure how to do it. or is there any other way of achiveing this?
Please help me at the earliest. Much Thanks.
Regards,Manivannan.P
|
|
|
|
|
Hi,
I have a very strange problem. I'm working with C# on Windows 2000.
The problem involves my module which is a dll.
When I try to debug, when I go over certain lines of code (not always the same one) the program exits and I see in the Output window:
Fatal execution engine error.
The program '[2976] <name>' has exited with code 0 (0x0).
Now to the strange part. It never happens if there are no breakpoints in the code.
It also doesn't happen if I'm running my dll from a test program in the same solution, only from another place.
More clues: What I see is that the debugger reaches the breakpoint, prepares to stop (I see the yellow highlight) and then crashes. It doesn't enter the function in that line. Another clue is that the function is usually a getter of a connection from another class (the connection exists - it is static), but it doesn't crash there if there s no breakpoint on it or if I debug through it. as I said it doesn't enter the function.
It was a bit long, but I will be really glad if someone could help me,
Thanks!
|
|
|
|
|
Hello,I want to be able to highlight a text and then run my program,which will simulate a Ctrl+c action so the text will be inserted into the clipboard.
Thanks in advance!
|
|
|
|
|
Use the SenKeys.Send function, you have to pass by a string which is formatted in a special way. i dont have it in my head, for instance pushing down Alt and down arrow at the same time should be written
SendKeys.Send("%{DOWN}")
% represents Alt
Regards
Hmitosh
|
|
|
|
|
Thanks for the help,but the problem now is that the Ctrl+c is sent to the running application.. let's say I'm using IE,I want to be able to highlight a word,press an icon that will acivate my program which will simulate ctrl+c and insert the selected word from IE to the clipBoard. I read something about changing the focus,is that a valid solution? and how is it done? thanks!
|
|
|
|
|
After getting very good answers on my question regarding "Calling C# functions from a DLL from within unmanaged C++" [^], I successfully decided to do CLR Hosting [^] and quickly got very good results implementing a usable wrapper around that CLR Hosting stuff.
So it all works very good except the startup time when I load the assembly with my code for the very first time only (through (_AppDomain::CreateInstance() ). Subsequent loads into a new host in the same running applications load fast.
Question: Is there a way to speed up creating an assembly instance?
E.g. when I start a .NET only application the application starts instantly, much faster than when I create the instance inside my .NET host. Maybe there is some "default" CLR floating around in the Windows system that I can re-use inside my .NET host instead of creating a new one?
--
Affordable Windows-based CMS: www.zeta-producer.com
|
|
|
|
|
Hey...I downloaded some code that uses System.Winform but my system complains that a Winform doesn't exist in the Sytem namespace.
I downloaded the .NET 2.0 Beta and the .NET SDK and it still doesn't exist. Where does the Winform object come from?
|
|
|
|
|
|
Hi,
Well, i have 4 Threads, they call the same function to send a File using HttpWebRequest.
I need to send the four photos at the same time.
The function is called at the same time, but only sends 2 at same time :\
Why?
<br />
byte[] buffer = new Byte[256]; <br />
int bytesRead = 0;<br />
while ( (bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0 )<br />
{<br />
requestStream.Write(buffer, 0, bytesRead);<br />
<br />
progress.Value += bytesRead;<br />
}<br />
Thanks.
|
|
|
|
|
|
There is actually a registry hack for it.
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]<br />
"MaxConnectionsPer1_0Server"=dword:00000019<br />
"MaxConnectionsPerServer"=dword:00000019
That should allow up to 10 simultaneous streams.
|
|
|
|
|
Or more specifically i want to get rid of the systemsound when the cursor is in a textbox and you hit the enter key, windows will automaticly play a soundeffect according to the soundeffect that is selected as standardsound (see controlpanel -> Sound and Sound devices -> Scroll down to Standard sound option). I suppose this sound can be useful when you want to notify the user, that the enter key is not applicable in a textbox, in my case however the enter key is supposed to work as an alternative to the tabkey. So in this case it's very annoying having to listening to that soundeffect each time.
I can always deselect the sound from the soundsetting dialogue in controlpanel, however this selection will reflect the whole system and remove the sound in all other cases where this sound occurs and that is not my intention, i just want to remove it from my application. Does anyone know how to solve this?
|
|
|
|
|
Not exactly the easiest thing in the programming world:
Read this[^] to understand how system sound notification occurs and (maybe) how to prevent them.
Yes, even I am blogging now!
|
|
|
|
|
I wouldn't go into changing sound events in the host's OS. Best solution is creating an inherited TextBox and overriding the ProcessDialogKey method:
public Class MyTextBox: TextBox
{
...
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData==Keys.Enter)
{
if (!this.Multiline)
{
ProcessDialogKey(Keys.Tab);
return true;
}
}
return base.ProcessDialogKey (keyData);
}
...
}
This will enable the enter key as a Tab input. I think its what ur looking for. Just add MyTextBoxes to your form instead of normal TextBoxes and ur all set.
|
|
|
|