It seems the most obvious thing, but I just can't work out how to get the length of bytes sent over a network using a TCPClient and TCPListener?
This is my code so far:
'Must listen on correct port- must be same as port client wants to connect on.
Const portNumber As Integer = 9999
Dim tcpListener As New TcpListener(IPAddress...
Hi everyone!
I'm using Moq & NUnit as a unit test framework.
I've written a method that is given a NetworkStream object as a parameter:
public static void ReadDataIntoBuffer(NetworkStream networkStream, Queue dataBuffer)
{
if ((networkStream != null) && (dataBuffer != null))
{
while (networkStream.DataAvailable)
{
...
Hey,
I'm having an issue with a socket programming job. I wrote a TCP client that sends commands via sockets/networkstream. I'm using Wireshark to look at the raw data that goes through the wires.
Everytime I send a "command" (meaning I Flush() the networkstream), the Wireshark application tells me that the checksum in the TCP Header is...
Can anyone point out the flaw in this code? I'm retrieving some HTML with TcpClient. NetworkStream.Read() never seems to finish when talking to an IIS server. If I go use the Fiddler proxy instead, it works fine, but when talking directly to the target server the .read() loop won't exit until the connection exceptions out with an error l...
Currently, there isn't a NetworkStream.Peek method in C#. What is the best way of implementing such a method which functions just like NetworkStream.ReadByte except that the returned byte is not actually removed from the Stream?
...
I have some code writen by me in C#
string host = new Uri(_url).Host;
IPHostEntry ipAddress = Dns.GetHostEntry(host);
IPEndPoint ip = new IPEndPoint(ipAddress.AddressList[0], 80);
using (Socket s = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
s.Connect(ip);
...
I'm building a simple client-server chat system.
The clients send data to the server and the server resends the data to all the other clients. I'm using the TcpListener and Network stream classes to send the data between the client and the server.
The fields I need to send are, for example: name, text, timestamp, etc. I separate them u...
A new instance of a TcpClient connects to a remote host. Its NetworkStream is retrieved and stored. Do I have to store the TcpClient itself as well to make sure it is not garbage collected?
In case you're going to answer "You have to store it to be able to dispose it":
In my specific case, the TcpClient is usually living for a long time...
I try to use stream.DataAvailable to judge if it is finished,but sometimes the value is false but after a little while it is true again,i have to set a counter and judge the end by the symbol '>' like this
int connectCounter = 0;
while (connectCounter < 1200)
{
if (stream.DataAvailable)
{
while (stream.DataAvailable)
...
Alright so here is what I have so far,
List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(f))
{
string line;
while ((line = r.ReadLine()) != null)
{
lines.Add(line);
}
}
foreach (string s in lines)
{
NetworkStream stream = irc.GetStream();
writer.WriteLine(USER);
writ...
Using a dotNET TcpClient if I have called an asynchronous BeginRead() on the associated network stream can I still call Write() on that stream on another thread?
Or do I have to lock() the TcpClient in the code that is called back from the BeginRead and the code that does the send?
Also if I close the TcpClient with:
client.GetStream(...
I have a call to Read on NetworkStream objeck, which uses Socket.Receive internally.
Say that no data is comming in. How long before the Read Method exits?
ReceiveTimeout is set to 0 (infinite timeout).
What if I unplug the internet cable? Will it exit?
...
I've got a DirectShow project where I want to capture and stream to a webserver. I have seen how to capture and create a file, but I'm looking for ideas on how to capture into something like a MemoryStream to transport through a NetworkStream. I'm also using the library DirectShowLib for the ability to write in C# if that makes any diffe...
I've an open TCP connection, and reading using NetworkStream.BeginRead(). Once the connection is closed at either end, the callback is called and the stream object is useless - like documentation says, EndRead() throws IOException or ObjectDisposedException depending in this case on which end terminated the connection.
Is it guaranteed ...
I am experimenting with the Tcp connections in .NET and I would like to send some data that is larger than the SendBufferSize proporty of the TcpClient object. Is it possible to send the data by simply writing to the network stream or do I need to cut it in pices and send those and at the other end create it again?
...
I just asked a question on how to send data larger than the SendBufferSize and the answer was that is would be send in a couple of parts.
My second question is how will this data be received? Will it be complete in the network stream or will it get it divided.
the first question: http://stackoverflow.com/questions/3097695/can-you-send-...
I'm trying to post to an ASP.NET Site via Sockets by sending the Raw HTTP Request information however; when trying to read the response I get
"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
Here is the code I am using
Public Function PerformGetRequest() As String
...
Hi
I am sending serialized objects via a NetWorkStream to another computer, on the receiving end I would like to deserialize these objects.
I will be sending many consecutive objects, when I am receiving data via the NetworkStream, how do I know when the first JSON Document ended in order to have JSON.NET Parse the document from the re...
Hello
Is there any way to have Json.net serialize an object directly to a NetworkStream?
In other words, have Json.net send the serialized result to the network as it serializes the object (in a streaming fashion).
I would like to avoid having to serialize the object to memory and then send it via the NetworkStream.
Any thoughts?
Re...
Hi all,
From the internet I got the way to read a huge string from a NetworkStream.
static NetworkStream ns = null;
static StringBuilder sb = null;
static byte[] buffer = null;
static int position = 0;
//.......................................
//other codes skipped for simplicity
//.......................................
priv...