tcplistener

Serializing object ready to send over TCPClient Stream

我与影子孤独终老i 提交于 2019-12-18 17:07:20
问题 I've got a server and client set up using TcpListener and TcpClient . I want to send an object to my server application for processing. I've discovered the using System.Runtime.Serialization and the following documentation, but I didn't want to faff around to find that I'm doing it in long winded way. The question: What is the best way to process and send an object over the TCP stream? Sending and receiving. Here's an example of my object: // Create a new house to send house newHouse = new

Serializing object ready to send over TCPClient Stream

百般思念 提交于 2019-12-18 17:07:03
问题 I've got a server and client set up using TcpListener and TcpClient . I want to send an object to my server application for processing. I've discovered the using System.Runtime.Serialization and the following documentation, but I didn't want to faff around to find that I'm doing it in long winded way. The question: What is the best way to process and send an object over the TCP stream? Sending and receiving. Here's an example of my object: // Create a new house to send house newHouse = new

C# TCP/IP simple chat with multiple-clients

强颜欢笑 提交于 2019-12-18 13:31:05
问题 I'm learning c# socket programming. So, I decided to make a TCP chat, the basic idea is that A client send data to the server, then the server broadcast it for all the clients online (in this case all the clients are in a dictionary). When there is 1 client connected, it works as expected, the problem is occurred when there is more than 1 client connected. Server: class Program { static void Main(string[] args) { Dictionary<int,TcpClient> list_clients = new Dictionary<int,TcpClient> (); int

TcpListener: How to listen on specific port on all interfaces?

安稳与你 提交于 2019-12-18 05:51:02
问题 There are three overloads for constructing a TcpListener: public TcpListener(int port); ( obsolete ) public TcpListener(IPEndPoint localEP) public TcpListener(IPAddress localaddr, int port) i want to listen on a particular port, but on all available interfaces. There was an overload available to do that, but it's been marked as obsolete . What is the new preferred/non-obsolete way to listen on a particular port on all interfaces with a TcpListener in .NET? For helpfulness sake, an IPEndPoint

C# High CPU usage on Listener thread, sleeping misses disconnect

左心房为你撑大大i 提交于 2019-12-17 17:10:48
问题 My connection handler is below (this is more for personal experimentation than production code) If I don't add a Thread.Sleep anywhere in the while loop, it starts sucking down CPU.. Conversely, if I do Sleep to alleviate the endless while-spam, I miss the disconnection.. The CPU goes up in direct proportion to the number of clients/threads running, so it's not the listener itself that's causing the high usage, it's the actual client thread posted below.. Anyone have any ideas on how to solve

how do i get TcpListener to accept multiple connections and work with each one individually?

一笑奈何 提交于 2019-12-17 08:31:03
问题 I have an SMTP listener that works well but is only able to receive one connection. My C# code is below and I am running it as a service. My goal is to have it runnign on a server and parsing multiple smtp messages sent to it. currently it parses the first message and stops working. how can I get it to accept the 2nd, 3rd, 4th... SMTP message and process it like it does the first? here is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using

Cannot connect to another computer over TCP

房东的猫 提交于 2019-12-14 03:02:29
问题 I am working on a project that transfers files over TCP. It is written in .NET 4.7. The program works while the client connects on the server that is on the same computer but when I send it to a friend and I try to connect it I get an error: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond Currently the program only sends some information about the file that

SslStream.AuthenticateAsServer exception - The server mode SSL must use a certificate with the associated private key

为君一笑 提交于 2019-12-13 18:13:03
问题 I am developing a proxy server application similar to CCProxy. Its working fine for HTTP but not HTTPS. Its throwing exception when AuthenticateAsServer() method is called on SslStream object. I also don't know whether I have supplied proper certificate, I don't know how to create a certificate. I just provided the certificate which came with the code that I downloaded online. Here is the code: private static void DoHttpProcessing(TcpClient client) { Stream clientStream = client.GetStream();

Tcp Listener and Client listening to specfic ip

被刻印的时光 ゝ 提交于 2019-12-13 07:58:27
问题 What i am trying to do is listen to a socket of 5000, which works perfectly with the code TcpListener listener = new TcpListener(IPAddress.Any, 5000); NetworkStream Network; TcpClient client; client = listener.AcceptTcpClient(); but when the server has two clients that connect to the server they both listen to the same message coming through as they are multi threaded, i dont want this to happen because with them reading each other they are removing bytes from the network stream. so my

TcpClient/Listener: Do I have to call Sockets.Close when my program ends?

一个人想着一个人 提交于 2019-12-13 07:00:56
问题 I'm using the TcpClient and TcpListener classes to establish a connection between two computers. I've read documentation and questions online, but can't seem to find the answer to this question: Is it necessary to call Sockets.Close() before the program ends, or will VB close all sockets which were opened by the program for me before it ends? In addition, what if the program crashes? From what I've seen, the suggested implementation of the TcpClient and TcpListener classes suggest closing the