|
Huh! That's cool
|
|
|
|
|
Or you can have a look in the shared source, nicer looking code there
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hey, just tell me where to find it
|
|
|
|
|
I have the following problem:
I use the folowing code on client side:
TcpClient client =...
byte[] buffer = new byte[MaxSize];
while(...)
{
networkStream ns = client.getNetworkStream();
readCount = ns.Read(buffer,0,MaxSize)
}
The loop is run on a separate thread, and it is deliberately
run forever. If the TcpClient really has something to
get from server, it really reads it (most probably from
intermediate buffers filled by lower level mechanisms)
And now description of the problem:
When I use this loop for the first time all works fine.
I mean that the complete first Read routine works fine.
(e.g when I want to get 500 KB data from socket, it is
partially fetched in chunks)
When the communication is over, the remote server closes
both stream and TcpClient:
SubsequentClient.Close();
SubsequentClientNS.Close();
In this moment I think, that the client code should
encouter some exception, but nothing is thrown... (?)
The things get worse when i want to use the loop again
and pool the TcpClient (which should me marked invalid now)
whether somethig has arrived =>
i call again Read method, and instad of some error/exception
i just get 0 (no data has been read) (this means, that the server
has not sent any data to client yet)
The question is:
How to make the client code know when the server has really closed
it's network stream (which it uses to send data to the client)
and/or closed TcpClient (which it obtained via Accept() method)
Thanx for any sugestions
|
|
|
|
|
If you want to know the internal socket status, just inherit the TcpClient class and add this code :
public class MyTcpClient : System.Net.Sockets.TcpClient
{
public MyTcpClient()
{
}
public bool Connected
{
get
{
return Client.Connected;
}
}
}
PS : Client is a protected property referencing the internal socket.
|
|
|
|
|
The Client.Connected boolean value allows me to find out whether _my_ code has closed the connection, not the remote side.
I've written a _very_ simple applications: Client and server:
If You can run this, You will see that the client, even after
closing the connection by the remote side can write to (or at least
it thinks so) or read from the stream.
The code:
Client:
static void Main(string[] args)
{
TcpClient tcpClient = new TcpClient("localhost",3000);
NetworkStream ns = tcpClient.GetStream();
byte[] bytesOut = Encoding.Unicode.GetBytes("disconnect_me");
ns.Write(bytesOut,0,bytesOut.Length);
ns.Write(bytesOut,0,bytesOut.Length);
}
The Server
static void Main(string[] args)
{
TcpListener listener = new TcpListener(3000);
listener.Start();
Console.WriteLine("The server is listening..");
TcpClient tcpClient = listener.AcceptTcpClient();
Console.WriteLine("Some client has connected to the server..");
NetworkStream ns = tcpClient.GetStream();
bool listening=true;
const int MaxSize=100;
int bytesRead=0;
byte[] buffer = new Byte[MaxSize];
while(listening)
{
bytesRead = ns.Read(buffer,0,MaxSize);
string command = Encoding.Unicode.GetString(buffer,0,bytesRead);
if(command.CompareTo("disconnect_me")==0)
{
Console.WriteLine("Client wants to be disconnected");
listening=false;
}
}
ns.Close();
tcpClient.Close();
Console.WriteLine("The connection with client has been closed.");
Console.ReadLine();
}
Thanks for any suggestions
|
|
|
|
|
I ought to know this by now, but how do you get a character by its ASCII character code? I'm simply wanting to make a character out of character code 176 ("°"). I don't know how to do it simply because I didn't need to until now. I've done some scouting around on MSDN, but haven't found anything that tells me.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Char c = (Char) 176;
MessageBox.Show ("char is " + c);
|
|
|
|
|
Hi, ive been working on porting some php code to c# and have hit an error....
the number two when encoded by the php pack() funditon to a double doesnt get read correctly by c# or im doing it wrong.
eg.
the number 1 gets packed and has the byte representation
63 240 0 0 0 0 0 0
8 byte representation.
the string that contains it contains "?ð "
i get 63 240 0 0 0 0 0 0 as the ascii codes when reading em byte by byte and typecasting to an int.
reading the 8 bytes using the BinaryReader.readDouble()
gives me 3.16202013338398E-322
BinaryReader.ReadUInt64(); gives 64
BinaryReader.ReadInt64(); gives 64
the number was encoded on a windows machine and is being read on a windows machine so the byte ordering should be the same.
the php documentation says using the "d" flag with the pack function gives a "d double (machine dependent size and representation) " the function is the same as the pack function in perl.
the number is packed using pack("d", $value) & unpacked using same flag....
1 = 63 240 0 0 0 0 0 0
2 = 64 0 0 0 0 0 0 0
3 = 64 8 0 0 0 0 0 0
4 = 64 16 0 0 0 0 0 0
i just cant seem to convert a string with those as the char code for each byte into the correct double.
any help would be great cause ive spent a week on this... ive got everything else working except for this which makes all the work ive put in useless...
if i know the algo to read and cant convert a double to the same format and that would be perfect...
is there something im not doing right?
thanks in advanced
nik
|
|
|
|
|
If I understand well, you are using a proprietary-formatted PHP stream, and expect to read it back using simple ConvertToInt32 method calls, which obviously have no knowledge of the underlying PHP format ?
My guess is that the issue will be solved by reverse engineering the actual PHP pack() function implementation first. Fortunately, you have the source code for PHP.
Good luck!
|
|
|
|
|
Hi!
Does anyone know, how I can access the extended file-properties that comes with the NTFS FileSystem ? There are for example: Title, Author, Comment, and so on.
I want to read and write in these fields from a programm. I searched the whole MSDN documentation and Knowledge Base for hours and the result is: Null, Nothing
Can anyone help me?
Thanks Peter
|
|
|
|
|
Use NTFS as keyword. Cp article[^] (Richard Deeming, C# code).
|
|
|
|
|
That's it! This is very helpfull.
Thx Peter.
|
|
|
|
|
How can i disable the ALt+F4 and Alt+Del+Ctrl because i want to disable these function during running my program.
babar
|
|
|
|
|
|
.S.Rod. wrote:
Writing a virus ?
Or a kiosk style program
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I have started to execute the instructions in "Creating a Distributed Application" walkthrough from VS .NET docs.
I did everything and when I had to add an web reference in my web and win clientgs. I got the following error, when trying to access the address:
http://localhost/AuthorsWebService/AuthorsWebService.vsdisco
Web Services
(none)
No Web References were found on this page.
Click for help on finding a Web Reference.
Errors
The document was not recognized as a known document type (WSDL, XML Schema, or Discovery document) for the following reason:
- The content type 'application/octet-stream' is not valid for an XML document.
Here is what appears in the browser for the Discovery
- <dynamicdiscovery xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">
<exclude path="_vti_cnf">
<exclude path="_vti_pvt">
<exclude path="_vti_log">
<exclude path="_vti_script">
<exclude path="_vti_txt">
<exclude path="Web References">
I was able to add a web reference and to complete the walkthrough after I have accessed:
http://localhost/AuthorsWebService/AuthorsService.asmx
On this page when I click the "service description" link I get an XML file too. Is this correct?
And what is wrong with the Discovery?
And one more question: does a web reference require source code changes and recompilation if the URL for the web service is changed?
Does this mean that a change of an URL requires a change of namespaces?
Thank you!
Z.
|
|
|
|
|
If you plan to post xml content, replace < with < and > with > in the tags.
|
|
|
|
|
yes I have noticed it but I wasn't allowed to edit the message.
|
|
|
|
|
Here the same message again with XML:
I have started to execute the instructions in "Creating a Distributed Application" walkthrough from VS .NET docs.
I did everything and when I had to add an web reference in my web and win clientgs. I got the following error, when trying to access the address:
http://localhost/AuthorsWebService/AuthorsWebService.vsdisco
Web Services
(none)
No Web References were found on this page.
Click for help on finding a Web Reference.
Errors
The document was not recognized as a known document type (WSDL, XML Schema, or Discovery document) for the following reason:
- The content type 'application/octet-stream' is not valid for an XML document.
Here is what appears in the browser for the Discovery
<?xml version="1.0" encoding="utf-8" ?>
- <dynamicDiscovery xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">
<exclude path="_vti_cnf" />
<exclude path="_vti_pvt" />
<exclude path="_vti_log" />
<exclude path="_vti_script" />
<exclude path="_vti_txt" />
<exclude path="Web References" />
</dynamicDiscovery>
I was able to add a web reference and to complete the walkthrough after I have accessed:
http://localhost/AuthorsWebService/AuthorsService.asmx
On this page when I click the "service description" link I get an XML file too. Is this correct?
And what is wrong with the Discovery?
And one more question: does a web reference require source code changes and recompilation if the URL for the web service is changed?
Does this mean that a change of an URL requires a change of namespaces?
Thank you!
Z.
|
|
|
|
|
I want to know how to use MS Internet Explore in my own form and automaticly fill some HTML elements(such as Text box, dropdown list box or radio box).
Is there any control that wrap the MS Internet Explore and can access the content(html string) and the Html Element?
I use C#.
Thanks in advance!!
Alan Shen
|
|
|
|
|
CodeProject article[^]. In short, the web browser control is obtained by going in Toolbox \ Customize and then insert the Microsoft Web Browser control. The html itself is provided by mshtml.dll one of the Microsoft.NET primary interop assemblies (c:\program files\Microsoft.NET\Primary interop assemblies\mshtml.dll).
|
|
|
|
|
Thank you very much.
Do you know how to control the Html elements in a HTML FORM?
|
|
|
|
|
I could put a few urls, but quite honestly programming is all about enjoying time discovering things yourself.
|
|
|
|
|
Hi All,
I have a program that assigns one TabPage to equal another.
tabControl1.TabPages[1] = tabControl1.TabPages[0]; The problem is this: the TabPages have controls on them and when I assign the pages as above the controls are no longer displayed. The controls are still there (one of the controls is the webbroswer and the page it points to has a popup) but I can't see them and they don't appear to be enabled because I can't tab to them or anything. Does anyone know how to fix this problem? I've tried using the Refresh and Update methods of the TabPage.
I made a small program to demonstrate this. You can d/l it from http://members.shaw.ca/theory/Tabs.zip[^]
Any help or ideas are appreciated. Thanks.
- monrobot13
|
|
|
|