tcpclient

Android Socket: java.net.SocketException: No route to host

青春壹個敷衍的年華 提交于 2019-12-01 17:32:15
I am trying to connect (through TCP) to the server running on my machine from the Android device. I have android.permission.INTERNET in my manifest file: <uses-permission android:name="android.permission.INTERNET"></uses-permission> I am able to connect using emulator but trying from the device throws an error: Android Socket: java.net.SocketException: No route to host Can anyone please help. Disabled wifi on my Android device and then re-enabled it and it worked. Your 192.168.1.114 address is a DHCP address (dynamically) assigned by your router to your PC. As a result it is visible to the

Android Socket: java.net.SocketException: No route to host

我只是一个虾纸丫 提交于 2019-12-01 16:12:57
问题 I am trying to connect (through TCP) to the server running on my machine from the Android device. I have android.permission.INTERNET in my manifest file: <uses-permission android:name="android.permission.INTERNET"></uses-permission> I am able to connect using emulator but trying from the device throws an error: Android Socket: java.net.SocketException: No route to host Can anyone please help. 回答1: Disabled wifi on my Android device and then re-enabled it and it worked. 回答2: Your 192.168.1.114

BeginReceive / BeginRead timeouts

夙愿已清 提交于 2019-12-01 15:04:59
I'm using a NetworkStream & TcpClient to asynchronously receive data using BeginRead. I need to apply a time-out to this operation, such that after a specified amount of time the read will be aborted. As far as I'm able to tell, this isn't supported on NetworkStream or TcpClient - there is a ReceiveTimeout property, but this appears to only apply to the synchronous equivalent - 'Read'. Even the underlying Socket class doesn't appear to support timeouts in its BeginReceive method. I've searched on this issue and the only suggested resolution I've seen is to set up another background thread to

BeginReceive / BeginRead timeouts

℡╲_俬逩灬. 提交于 2019-12-01 13:55:29
问题 I'm using a NetworkStream & TcpClient to asynchronously receive data using BeginRead. I need to apply a time-out to this operation, such that after a specified amount of time the read will be aborted. As far as I'm able to tell, this isn't supported on NetworkStream or TcpClient - there is a ReceiveTimeout property, but this appears to only apply to the synchronous equivalent - 'Read'. Even the underlying Socket class doesn't appear to support timeouts in its BeginReceive method. I've

How to ensure NetworkStream to send data immediately without closing the Stream or TcpClient?

℡╲_俬逩灬. 提交于 2019-12-01 12:46:08
I have a very simple code snippet that tries to send data via TcpClient and its associated NetworkStream . var client = new TcpClient("xxx.xxx.xxx.xxx", 1234); NetworkStream stream = client.GetStream(); byte[] buffer = Encoding.ASCII.GetBytes(str); stream.Write(buffer, 0, buffer.Length); I've found that usually the data won't be sent immediately after stream.Write() . If I add client.Close() or stream.Close() then data will be sent. However, in my case, I'm trying to wait for the server to send some ACK message back so I want to reuse the original NetworkStream without closing either the

C# Sockets and Multithreading

吃可爱长大的小学妹 提交于 2019-12-01 12:31:08
I am trying to learn more about sockets and threading in c#. I have come across a lot of good resources online to help get me started. The program I made so far, is a simple "man-in-the-middle" application. It's designed as the following: client <--> [application] <--> server Given the following code, how can I prevent this thread from running at 100% CPU? How can I have the thread wait and block for data and not exit when the client / server is idle? while (true) { lock (ClientState) { checkConnectionStatus(client, server); } if (clientStream.CanRead && clientStream.DataAvailable) { Byte[]

How to ensure NetworkStream to send data immediately without closing the Stream or TcpClient?

梦想与她 提交于 2019-12-01 11:18:12
问题 I have a very simple code snippet that tries to send data via TcpClient and its associated NetworkStream . var client = new TcpClient("xxx.xxx.xxx.xxx", 1234); NetworkStream stream = client.GetStream(); byte[] buffer = Encoding.ASCII.GetBytes(str); stream.Write(buffer, 0, buffer.Length); I've found that usually the data won't be sent immediately after stream.Write() . If I add client.Close() or stream.Close() then data will be sent. However, in my case, I'm trying to wait for the server to

C# Sockets and Multithreading

人盡茶涼 提交于 2019-12-01 10:55:21
问题 I am trying to learn more about sockets and threading in c#. I have come across a lot of good resources online to help get me started. The program I made so far, is a simple "man-in-the-middle" application. It's designed as the following: client <--> [application] <--> server Given the following code, how can I prevent this thread from running at 100% CPU? How can I have the thread wait and block for data and not exit when the client / server is idle? while (true) { lock (ClientState) {

How to check the connection state of a TCP Server (Socket) with TCP Client in VB.NET

≯℡__Kan透↙ 提交于 2019-12-01 10:53:52
For almost a week I am reading and trying to find a solution for checking connection state using a TCP Client (using socket class) In my scenario I have a TCP Client that is connected to a server (it is not controlled by me) and i want that from time to time to check the connection state, and reconnect if necessary. I have read a lot of information on the internet but i did not find a suitable solution. Briefly, these are the methods that i have found on the internet and try to implement. But unfortunatelly, i have found some scenarios where the TCP Server is closed and the TCP Client is still

How to check the connection state of a TCP Server (Socket) with TCP Client in VB.NET

一笑奈何 提交于 2019-12-01 08:45:18
问题 For almost a week I am reading and trying to find a solution for checking connection state using a TCP Client (using socket class) In my scenario I have a TCP Client that is connected to a server (it is not controlled by me) and i want that from time to time to check the connection state, and reconnect if necessary. I have read a lot of information on the internet but i did not find a suitable solution. Briefly, these are the methods that i have found on the internet and try to implement. But