tcplistener

How can I send data with a TcpListener, and wait for the response ?

I have the following code: using (TcpClient client = new TcpClient()) { client.Connect(host, port); using (SslStream stream = new SslStream(client.GetStream(), true)) { stream.AuthenticateAsClient(host); stream.Write(System.Text.Encoding.ASCII.GetBytes(dataToSend)); int byteRead = 0; byte[] buffer = n...

TCPlistener.BeginAcceptSocket - async question

Hi, Some time ago I have payed to a programmer for doing multithread server. In the meantime I have learned C# a bit and now I think I can see the slowndown problem - I was told by that guy that nothing is processed on the main thread (Form) so it cannot be frozen..but it is. But I think that altough BeginAcceptSocket is async operation,...

Creating an 802.11 transmitter and reading the data from a WiFi router.

There are 2 parts to this question. Feel free just to give me URLs to articles or suggest books, too, as the answer is probably a bit in depth for a quick forum response. 1) I need to sense the wattage flowing through a pair of wires and transmit data about it via 802.11. I guess a micro controller is involved, but I'm not sure where to...

How to test a TCP server implementation?

I have written a TCP server implementation using which I created an application which works as TCP echo service. Now I want to test this echo server in terms of How many connections it can handle What is the response time How much memory and CPU it uses Please can you suggest any standard method/tools to test this echo server. I und...

Problem with TCPListener

I have some kind of problem and I can't check this at home if its working or not. Here is the code using System; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; using System.Net.Security; class Program { private static IPAddress ipAddress = IPAddress.Parse("127.0.0.1"); private static int port = 600...

Receving and sending data in C#

Im still trying to improve a little bit what I wrote before. Now I faced a problem with receiving data. I have a program which I use to send string using tcpClient to a program in which Im listening on a specified port. It works fine so I decided to send data forward one more time public static void receiveThread() { while (true) ...

How can I stop a thread in C# ?

I've created a Client-Server application, and on the Server I want to have the oportunity to stop the server and then start it again. The problem is that I can't stop the Thread that listen for Tcp Connections. How can I close a Thread in C#? Thanks. private void KeepServer(){ while (this.connected) { tcpClient = tls....

How could I know that BeginAcceptSocket callback needs IAsyncResult parameter?

Hi, I am curious where can I find out that AcceptClient as a callback of BeginAcceptSocket needs to have IAsyncResult as a parameter. In the MSDN article there is only mentioned that return value of BeginAcceptSocket is IAsyncresult. But how could I know that it has to be passed to callback? Thanks! public server(int port) { ...

Bind TCP server to specific adaptor

How can I specify which adaptor to begin listening on? I have an application running on a PC which happens to have 2 network adaptors running on different subnets (one network for Business LAN infrastructure, one for TCP cameras) I have a class which opens up a TCP server and listens on a specific port for connections coming in from cl...

how to make server accept port number from range of 5555-9999

I am using a default port now. TcpListener serverSocket = new TcpListener(9999); using System; using System.Threading; using System.Net.Sockets; using System.Text; using System.Collections; namespace ConsoleApplication1 { class Program { public static Hashtable clientsList = new Hashtable(); static void Main(s...

how to constrain the number of clients a TcpListener can accept?

is there a way to limit the number of clients a tcpListener can accept? ...

Help with windows TCP Port communication

I'm new to understanding how interprocess communication works. I"m working with two applications on my localmachine, a Source Application and a Server Application. The Source application broadcasts files through a configured port on my pc. The Server application listens for those files and exposes them to the internet for users to stream...

TcpListener.Start() does not open the port

Hello, I have a class that inherits from the TcpListener, this class Shadows the Start method just to call the base Start() and the base BeginAcceptTcpClient(). From time to time the method is called but the port is not opened (netstat does not show the port open). The class looks like this Public Class ExtendedTcpListener Inherit...

Jumbled byte array after using TcpClient and TcpListener

I want to use the TcpClient and TcpListener to send an mp3 file over a network. I implemented a solution of this using sockets, but there were some issues so I am investigating a new/better way to send a file. I create a byte array which looks like this: length_of_filename|filename|file This should then be transmitted using the above m...

Why we need to read() before write() in TCP server program?

Hi, As per my understanding a simple TCP server will be coded as follows. socket() - bind() - listen() - accept() - read() - write() The clients will be written as follows. socket() - bind()(Optional) - connect() - write() - read() Please note the order difference in read() and write() calls between client and server program. Is it...

There's a black hole in my server (TcpClient, TcpListener)

Hi, I'm trying to build a server that will receive files sent by clients over a network. If the client decides to send one file at a time, there's no problem, I get the file as I expected, but if it tries to send more than one I only get the first one. Here's the server code: I'm using one Thread per connected client public void Proce...

.NET TCPListener limitation ?

Hi all, I have a question about the usage of TCPListener in .NET... I am thinking about a client/server application and being new to this kind of application I have search a bit around the web and the solution which come the more often is to create a new thread for each new client connection. This solution seem fine but I was wondering...

~1 second TcpListener Pending()/AcceptTcpClient() lag

Probably just watch this video: http://screencast.com/t/OWE1OWVkO As you see, the delay between a connection being initiated (via telnet or firefox) and my program first getting word of it. Here's the code that waits for the connection public IDLServer(System.Net.IPAddress addr,int port) { Listener = new TcpLis...

TcpListener is queuing connections faster than I can clear them

As I understand it, TcpListener will queue connections once you call Start(). Each time you call AcceptTcpClient (or BeginAcceptTcpClient), it will dequeue one item from the queue. If we load test our TcpListener app by sending 1,000 connections to it at once, the queue builds far faster than we can clear it, leading (eventually) to tim...

SocketException preventing use of C# TCPListener in Windows Service

I have a Windows Service that does the following when started. When running via a Console application it works fine, but once I put in a Windows Service I get the below exception. Here is what I have tried so far: Disabled the firewall, also tried adding explicit exclusions for the exe, port, and protocol Checked CAS Policy Config, sho...