tcpclient

Terminate loopless thread instantly without Abort or Suspend

自作多情 提交于 2019-12-04 16:00:00
I am implementing a protocol library. Here a simplified description. The main thread within the main function will always check, whether some data is available on the the networkstream (within a tcpclient). Let us say response is the received message and thread is a running thread. thread = new Thread(new ThreadStart(function)); thread.IsBackground = true; thread.Start(); while(true){ response = receiveMessage(); if (response != null) { thread.Suspend(); //I am searching for an alternative for the line above and not thread.Abort(). thread2 = new Thread(new ThreadStart(function2)); thread2

TCP IP Listener in windows Service

三世轮回 提交于 2019-12-04 15:49:44
问题 I'm trying to create a windows service that needs to run in the background and listen for incoming traffic (a normal and regular TCP listener) my code is: private TcpListener server; public void startServer() { // EventLog.WriteEntry(source, "connected on: " + ipAddress.ToString() + " port: " + Service1.Port.ToString()); server = new TcpListener(IPAddress.Parse("127.0.0.1"), Service1.Port); server.Start(); while (true) { var client = server.AcceptTcpClient(); new Thread(work).Start(client); }

TcpClient; NetworkStream; ReadAsync; C#

左心房为你撑大大i 提交于 2019-12-04 14:12:13
Please excuse my lack of knowledge regarding Tasks and Async. Using the TcpClient class I am creating a connection with an available server: void async RunClientAsync() { TcpClient client = new TcpClient(); try { await client.ConnectAsync(IPAddress.Parse("1.1.1.1"), 8889); Task.Start(() => ReadClientAsync(client)); } catch (Exception ex) { HandleException(ex); } } // ----- void async ReadClientAsync(TcpClient client) { byte[] bf = new byte[2048]; try { while(true) { int br = await client.NetworkStream().ReadAsync(); if (br > 0) { HandleInboundData(bf, br); } } } catch (Exception ex) {

Can you send a file larger that the SendBufferSize throuh a TcpClient?

核能气质少年 提交于 2019-12-04 13:08:57
I am experimenting with the Tcp connections in .NET and I would like to send some data that is larger than the SendBufferSize proporty of the TcpClient object. Is it possible to send the data by simply writing to the network stream or do I need to cut it in pices and send those and at the other end create it again? From MSDN : If the network buffer is smaller than the amount of data you provide the Write method, several network send operations will be performed for every call you make to the Write method. You only need to call Write once, the TcpClient will handle splitting it into multiple

Receiving and sending data in C#

落爺英雄遲暮 提交于 2019-12-04 12:06:29
问题 I'm 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) { TcpListener tcpListener = new TcpListener(IPAddress.Any, port); tcpListener.Start(); Console.WriteLine("Waiting for connection..."); TcpClient tcpClient =

Windows automate telnet

若如初见. 提交于 2019-12-04 10:07:49
问题 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 void Main(string[] args) { ProcessStartInfo cmdStartInfo = new ProcessStartInfo(); cmdStartInfo.FileName = @"C:\Windows\System32\cmd.exe"; cmdStartInfo.RedirectStandardOutput = true; cmdStartInfo.RedirectStandardError = true; cmdStartInfo.RedirectStandardInput = true

How to fix TcpClient Ip Header Bad Checksum

梦想与她 提交于 2019-12-04 09:39:52
I'm using System.Net.Sockets.TcpClient class but whenever I send custom packet over the network I'm seeing bad checksum on my wireshark capture. How can I fix it? The problem is that you have checksum offloading set on your network interface. This causes your network card to calculate the checksum and not Windows. WireShark will detect this as incorrect checksums, but they really aren't. In the properties of your network interface, if you click [Configure], the [Advanced] tab has a [Offload Checksum] item. If you set that to [Disabled], WireShark will display that the checksums are correct. 来源

What are the benefits of using TcpClient over a Socket directly?

心不动则不痛 提交于 2019-12-04 08:57:44
问题 I understand that a TcpClient is a wrapper around the socket class, and I can access the underlying socket if using the TcpClient, but what exactly does the wrapper do? When using the TCPClient do i need to keep calling Receive() like I do with a socket or does the wrapper ensure all my data appears? Lastly, can I use the TcpClient on both the server and the client to wrap the socket (after using TcpListener to accept the original connection on the server) 回答1: what exactly does the wrapper

C# TcpClient.Connect via a proxy

蹲街弑〆低调 提交于 2019-12-04 08:38:37
问题 I've searched high and low trying to figure this out, but everything I've seen so far, people are just telling me to use other methods. With that out of the way, my issue is that I'm trying to connect to a server through a TcpClient using a socks 5 proxy My current setup is: Client = new TcpClient(); Client.Connect(EndPoint); NetworkStream = Client.GetStream(); Stream = new new BufferedStream(NetworkStream); Stream.Write...//Write Packet information etc I'm not sure if I've missed any

How to use SSL in TcpClient class

倾然丶 夕夏残阳落幕 提交于 2019-12-04 07:46:13
问题 In the .NET framework there is a class TcpClient to retrieve emails from an email server. The TcpClient class has 4 constructors to connect with the server which take at most two parameters. It works fine with those servers which does not use SSL. But gmail or many other email providers use SSL for IMAP. I can connect with gmail server but can not authenticate with email_id and password. My code for authenticate user is public void AuthenticateUser(string username, string password) { _imapSw