Questions tagged [tcpclient]

.NET Framework class, providing client connections for TCP network services.

2541 questions
21
votes
2 answers

How to let kernel choose a port number in the range (1024,5000) in TCP socket programming

When I run the following code: struct sockaddr_in sin; int addrlen; addrlen=sizeof(sin); memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr=inet_addr("123.456.789.112"); sin.sin_port=htons(0); // so that the…
Anonymous
  • 4,133
  • 10
  • 31
  • 38
20
votes
7 answers

TCP\IP client - EHOSTUNREACH (No route to host)

I am trying to develop a client server TCP/IP application. I have a server running on my PC and the client app is running on the mobile. They both are in the same Wi-Fi network, but I cannot establish a connection between them. While debugging the…
sash
  • 1,124
  • 2
  • 15
  • 32
18
votes
4 answers

Does one need to close both NetworkStream and TcpClient, or just TcpClient?

I'm reading the documentation on TcpClient.Close() and noticed this: Calling this method will eventually result in the close of the associated Socket and will also close the associated NetworkStream that is used to send and receive data if one was…
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
18
votes
3 answers

Windows automate telnet

I would like to run a set of commands that would typically be run in telnet(from c#). For example I would like to run the following using System; using System.Diagnostics; namespace InteractWithConsoleApp { class Program { static…
Lime
  • 13,400
  • 11
  • 56
  • 88
18
votes
3 answers

Proper order for closing TcpListener and TcpClient connections (which side should be the active close)

I read this answer on a previous question which says: So the peer that initiates the termination – i.e. calls close() first – will end up in the TIME_WAIT state. [...] However, it can be a problem with lots of sockets in TIME_WAIT state on a server…
Paul Stovell
  • 32,377
  • 16
  • 80
  • 108
17
votes
4 answers

Configure socket ACK timeout?

Is there a way to configure the timeout in which a socket expects to receive an ACK for sent data before it decides that the connection has failed? I'm aware this can be done at the application level as well, but since every packet I send is ACK'd…
David Pfeffer
  • 38,869
  • 30
  • 127
  • 202
17
votes
8 answers

How to get all data from NetworkStream

I am trying to read all data present in the buffer of the Machine connected through TCP/IP but i don't know why i am not getting all data ,some data is getting Missed. Here is the code that i am using .. using (NetworkStream stream =…
shubham Hegdey
  • 507
  • 5
  • 8
  • 15
16
votes
2 answers

BeginReceive / BeginRead timeouts

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…
Barg
  • 2,968
  • 7
  • 26
  • 28
16
votes
4 answers

Send typed objects through tcp or sockets

I’m having trouble creating a network interface for a very simple game I’ve made in Xna. I would simply need to send objects through a TCP client / Socket. Ex: I have a class named “Player”. In every Player, there’s a field name “Info”, of type…
Philippe Paré
  • 4,279
  • 5
  • 36
  • 56
15
votes
3 answers

Simple tcp client examples in emacs elisp?

I'm trying to learn emacs elisp and trying to write a little program to connect to a TCP/IP port and process records that come back. In one case I'll be parsing CSV data and in the another, I'll be parsing JSON (e.g. from GPSD, and json.el…
Kurt Schwehr
  • 2,638
  • 3
  • 24
  • 41
15
votes
2 answers

Python - How to check if socket is still connected

I have the following code, which is self explanatory: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(host, port) s.send("some data") # don't close socket just yet... # do some other stuff with the data (normal string operations) if…
AK_
  • 1,879
  • 4
  • 21
  • 30
15
votes
2 answers

How can TcpClient implement IDisposable and not have a public Dispose method?

Just as the title says: How can TcpClient implement IDisposable and not have a public Dispose method?
CannibalSmith
  • 4,742
  • 10
  • 44
  • 52
14
votes
4 answers

How to use Tor control protocol in C#?

I'm trying to send commands to the Tor control port programmatically to make it refresh the chain. I haven't been able to find any examples in C#, and my solution's not working. The request times out. I have the service running, and I can see it…
Edgar
  • 4,348
  • 4
  • 40
  • 59
14
votes
2 answers

How to establish a SSL enabled TCP/IP Connection in Ruby

I need to establish a TCP connection with my server which has a SSL enabled port, that I need to access. I need to send a XML file and get the response from the server. Before the SSL was enabled, I was able to get the data from the server using…
Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88
14
votes
1 answer

Best way to wait for TcpClient data to become available?

while (TcpClient.Client.Available == 0) { Thread.Sleep(5); } Is there a better way to do this?
Jader Dias
  • 88,211
  • 155
  • 421
  • 625