tcpclient

How to handle a TCP connection in background? for Poker app server-client app

纵然是瞬间 提交于 2019-12-08 03:28:00
问题 I am working on Poker app based on server-client based app. When Poker App goes to the background after some time TCP/IP connection lost because app unable to send/recieve any packet to/from the server. Sever ends socket connection. how can i able to establish connection for long time and update my game UI 回答1: The topic you asked for, is called "Background Execution". First: You can't update the UI while the app enters the background. But you will be able to finish your API-Requests to the

Are there any cases when TcpClient.Close or Socket.Close(0) could block my code?

a 夏天 提交于 2019-12-08 02:55:53
问题 As it's not specified that Close method is thread safe I should call it from the lock. How can I be sure that it will not block my thread? Should I disable LingerState or can it be enabled? btw do I need to call both TcpClient.Close and TcpClient.Client.Close? 回答1: According to the documentation for TcpClient.Close, calling this method disposes the instance. A quick look in ILSpy reveals that it simply calls Dispose , which calls Dispose(true) . Furthermore, the documentation states that

c# socket send data mismatch server data

依然范特西╮ 提交于 2019-12-07 22:59:04
问题 while sending byte[] data via socket (a/sync) i'm getting on messagereceived event mismatch data. For example like this client: 2013-05-20 12:03:09.6929|DEBUG|Tcp|SendAsync_Completed: Sent ( ; T A , 59 84 65 13 10 ) to 127.0.0.1:10002 (Table)! 2013-05-20 12:03:09.8619|DEBUG|Tcp|SendAsync_Completed: Sent ( ; T A , 59 84 65 13 10 ) to 127.0.0.1:10002 (Table)! 2013-05-20 12:03:10.0249|DEBUG|Tcp|SendAsync_Completed: Sent ( ; T A , 59 84 65 13 10 ) to 127.0.0.1:10002 (Table)! 2013-05-20 12:03:10

No connection could be made because the target machine actively refuses it

我们两清 提交于 2019-12-07 18:02:05
问题 I'm working on a simple hello world TCP/IP client server app in C# and am unable to get my client to connect. Can anyone offer any additional troubleshooting steps? I'm starting to run out of ideas... Here are the relevant sections of code: server: Console.Out.WriteLine("About to bind address"); IPAddress ipAd = IPAddress.Parse("127.0.0.1"); Console.Out.WriteLine("Choose a port to bind..."); String port = Console.In.ReadLine(); int iPort = Int32.Parse(port); TcpListener myList = new

Sending and Receiving XML data over TCP

巧了我就是萌 提交于 2019-12-07 16:21:18
问题 I've been trying to figure out how to send and receive XML Data over a TCP Server. I'm coming from a java programming background so i'm a bit out of my depth here. My program works if i'm sending just plain text, however once I try to send the xml data it just hangs. The server never receives the message. I've been searching for code to do this and haven't found any luck, i've seen lots of code samples online that don't work. please if any of you can solve this problem I would be very

C# Mutlti-threading file transfer using TCP

北慕城南 提交于 2019-12-07 16:02:32
I am designing TCP server for receiving the file from client. Its working for one client. But Server need to respond multiple clients. I don't know how receive multiple files from clients at a same time. Please help me. Server Code: public partial class Form1 : Form { Thread t1; int flag = 0; string receivedPath = "yok"; public delegate void MyDelegate(); private string fileName; public Form1() { t1 = new Thread(new ThreadStart(StartListening)); t1.Start(); InitializeComponent(); } public class StateObject { // Client socket. public Socket workSocket = null; public const int BufferSize = 8096;

c# SSL TCPServer stuck at SsLStream.AuthenticateAsServer()

大兔子大兔子 提交于 2019-12-07 11:53:59
问题 Storyline: I wanted to make my very own webserver in c#(first attempt). It went well(I was using Visual Studio to code the application and Firefox to check if I was doing right) and I managed to make a basic TCPServer. As I was trying to add SSL support to it I encountered a problem. I have been trying to authenticate as a TcpServer with SSL support using SSLStream.AuthenticateAsServer([self-signed certificate]) for the last 7 days Problem: As I get the [Upgrade-Insecure-Requests: 1] from my

How to get page via TcpClient?

余生长醉 提交于 2019-12-07 10:27:06
问题 I'm trying to send a GET request to a page via TCP stream. Here's what my code looks like: public class SocketLevelWebClient { public string SendWebRequest(string url, string request) { using(TcpClient tc = new TcpClient()) { tc.Connect(url, 80); using (NetworkStream ns = tc.GetStream()) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(ns)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(ns)) { sw.Write(request); sw.Flush(); return sr.ReadToEnd(); } } } } } And

Why does Java read random amounts from a socket but not the whole message?

一个人想着一个人 提交于 2019-12-07 09:56:54
问题 I am working on a project and have a question about Java sockets. The source file which can be found here. After successfully transmitting the file size in plain text I need to transfer binary data. (DVD .Vob files) I have a loop such as // Read this files size long fileSize = Integer.parseInt(in.readLine()); // Read the block size they are going to use int blockSize = Integer.parseInt(in.readLine()); byte[] buffer = new byte[blockSize]; // Bytes "red" long bytesRead = 0; int read = 0; while

Cancel C# 4.5 TcpClient ReadAsync by timeout

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 04:47:01
问题 What would the proper way to cancel TcpClient ReadAsync operation by timeout and catch this timeout event in .NET 4.5? TcpClient.ReadTimeout seems to be applied to the sync Read only. UPDATE: Tried tro apply the approach desribed here Cancelling an Asynchronous Operation var buffer = new byte[4096]; CancellationTokenSource cts = new CancellationTokenSource(5000); int amountRead = await tcpClientStream.ReadAsync(buffer, 0, 4096, cts.Token); but it never cancels by timeout. Is anything wrong?