networkstream

C# Setting WriteTimeout / ReadTimeout on Network Stream Makes No Difference?

前提是你 提交于 2019-12-25 02:22:50
问题 I have following method code in my Xamarin.Forms application using (TcpClient client = new TcpClient(ip, port)) using (NetworkStream stream = client.GetStream()) { byte[] messageBytes = PrepareMessageBytes(); // // Setting these seam to have no effect // stream.WriteTimeout = (int)TimeSpan.FromSeconds(10).TotalMilliseconds; stream.ReadTimeout = (int)TimeSpan.FromSeconds(10).TotalMilliseconds; // // I have set read and write timeouts above but when // hitting this line, app hangs indefinitely?

XmlSerializer Won't Deserialize over NetworkStream

蓝咒 提交于 2019-12-25 01:47:01
问题 I'm looking to implement a simple Client/Server setup that can transfer a serialized EmailRequest object (using XmlSerializer ) from the client to the server, to be used to send an email. Server class Program { private static void Main() { try { TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8888); listener.Start(); while (true) { Console.WriteLine("Waiting for request.."); TcpClient client = listener.AcceptTcpClient(); NetworkStream stream = client.GetStream();

memorystream copyto network stream issues

吃可爱长大的小学妹 提交于 2019-12-24 06:49:33
问题 I'm having a problem with this code here. using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms,SerializableClassOfDoom); ms.Position = 0; byte[] messsize = BitConverter.GetBytes(ms.Length); ms.Write(messsize, 0, messsize.Length); NetworkStream ns = Sock.GetStream(); ms.CopyTo(ns); //ms.Close(); } I can't figure out what's happening here, or why it's not working. It seems like eather it doesn't copy, or it closes the network stream, or

Having trouble sending three or more packets consecutively

↘锁芯ラ 提交于 2019-12-24 00:31:53
问题 I am trying to implement a Client/Server model using TCpClient , with its Networkstream.Write()/Read() functions sending/receiving a byte array. It works most the time, except if I try to send three or more byte arrays in a row right after one another. The client says it sends them all, but the server only receives the first two. Below is the code I use to write from client to server. byte[] buffer = p.toByteArray(level); stream.Write(buffer, 0, buffer.Length); stream.Flush(); Is it

Reading NetworkStream doesn't advance stream

人盡茶涼 提交于 2019-12-23 23:08:07
问题 I have a client-server application where the server transmits a 4-byte integer specifying how large the next transmission is going to be. When I read the 4-byte integer on the client side (specifying FILE_SIZE), the next time I read the stream I get FILE_SIZE + 4 bytes read. Do I need to specify the offset to 4 when reading from this stream, or is there a way to automatically advance the NetworkStream so my offset can always be 0? SERVER NetworkStream theStream = theClient.getStream(); //...

TcpClient/NetworkStream not detecting disconnection

不想你离开。 提交于 2019-12-23 10:07:44
问题 I created a simple persistent socket connection for our game using TcpClient and NetworkStream . There's no problem connecting, sending messages, and disconnecting normally (quitting app/server shuts down/etc). However, I'm having some problems where, in certain cases, the client isn't detecting a disconnection from the server. The easiest way I have of testing this is to pull out the network cable on the wifi box, or set the phone to airplane mode, but it's happened in the middle of a game

How to allow a Server to accept both SSL and plain text (insecure) connections?

冷暖自知 提交于 2019-12-22 05:45:31
问题 I am trying to create a server that can accept both secure SSL and insecure plain text connection (for backwards compatibility). My code is almost working except the first transmitted data received from an insecure client loses the first 5 bytes (chars) at the server. More specificially if I transmit 30 bytes on an insecure connection, when the server gets to the OnClientDataReceived() function, the line " int iRx = nwStream.EndRead(asyn); ", then iRx = 25 . Any subsequent messages

async / await vs BeginRead, EndRead

廉价感情. 提交于 2019-12-22 05:14:40
问题 I don't quite 'get' async and await yet, and I'm looking for some clarification around a particular problem I'm about to solve. Basically, I need to write some code that'll handle a TCP connection. It'll essentially just receive data and process it until the connection is closed. I'd normally write this code using the NetworkStream BeginRead and EndRead pattern, but since the async / await pattern is much cleaner, I'm tempted to use that instead. However, since I admittedly don't fully

java.io.IOException: Permission denied on network folder

狂风中的少年 提交于 2019-12-21 14:51:02
问题 i'm having the the post's title error when trying to write a file on a window folder , mounted on unix system. I've developed a web service which runs inside a Tomcat 6 on a linux os and need to write on a windows network folder. System administrators have mounted it on the Linux sever and have no problem to create and modify a file on it. When i try to execute the posted code i get the following exception : Permission denied java.io.IOException: Permission denied at java.io.UnixFileSystem

C# NetworkStream.Read oddity

↘锁芯ラ 提交于 2019-12-21 09:27:49
问题 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 like "the remote server has closed the connection". internal TcpClient Client { get; set; } /// bunch of other code here... try { NetworkStream ns = Client