tcpclient

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

江枫思渺然 提交于 2019-12-03 11:27:57
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 created. So, correct me if I'm wrong but this says that if one calls Close() on the TcpClient that the NetworkStream will also be closed. So then why at the end of the code example are both Close() called? networkStream.Close(); tcpClient.Close(); Would it be just as fine to only call tcpClient.Close(); ? Responding to this question since no one else

Tcp Client two way communication help

拜拜、爱过 提交于 2019-12-03 10:14:54
I want to communicate between two applications or winforms in C# using clients and server its like i want a server continiously listening to incoming messages from a client or clients and when the msg is received i want to reply back to the client that sent the information for processing can any one help with code example Sounds like a good case for WCF using netTcpBinding in an intranet environment! :-) Check out these intros to WCF: Getting started with WCF WCF Templates and Tools WCF Developer Center WCF Getting Started - Videos, Screencasts, Whitepapers There's an especially good series of

TCP IP Listener in windows Service

房东的猫 提交于 2019-12-03 08:57: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); } public void work(object client) { string msg = null; var clientLocal = (TcpClient)client; using

How to use Tor control protocol in C#?

大兔子大兔子 提交于 2019-12-03 07:20:21
问题 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 listening on the control port. public string Refresh() { TcpClient client = new TcpClient("localhost", 9051); string response = string.Empty; string authenticate = MakeTcpRequest("AUTHENTICATE\r\n", client); if (authenticate.Equals("250")) { response

Windows automate telnet

匆匆过客 提交于 2019-12-03 05:01:37
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; cmdStartInfo.UseShellExecute = false; cmdStartInfo.CreateNoWindow = true; Process cmdProcess = new

Stopping a TcpListener after calling BeginAcceptTcpClient

妖精的绣舞 提交于 2019-12-03 04:56:11
问题 I have this code... internal static void Start() { TcpListener listenerSocket = new TcpListener(IPAddress.Any, 32599); listenerSocket.Start(); listenerSocket.BeginAcceptTcpClient(new AsyncCallback(AcceptClient), null); } Then my call back function looks like this... private static void AcceptClient(IAsyncResult asyncResult) { MessageHandler handler = new MessageHandler(listenerSocket.EndAcceptTcpClient(asyncResult)); ThreadPool.QueueUserWorkItem((object state) => handler.Process());

TcpClient vs Socket when dealing with asynchronousy

a 夏天 提交于 2019-12-03 03:42:56
问题 This is not yet another TcpClient vs Socket. TcpClient is a wrapper arround the Socket class to ease development, also exposing the underlying Socket. still ... On the MSDN library page for TcpClient class, one can read the following remark : The TcpClient class provides simple methods for connecting, sending, and receiving stream data over a network in synchronous blocking mode. And for the Socket class : The Socket class allows you to perform both synchronous and asynchronous data transfer

Error: TCP Provider: Error code 0x2746. During the Sql setup in linux through terminal

半腔热情 提交于 2019-12-03 02:36:13
问题 I am trying to setup the ms-sql server in my linux by following the documentation https://docs.microsoft.com/pl-pl/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-2017 The SQL server status is Active(Running) I am getting the following error while executing the command sqlcmd -S localhost -U SA -P '<YourPassword>' Error: Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable

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

笑着哭i 提交于 2019-12-03 01:29:40
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) what exactly does the wrapper do? Let me explain this with an example. You have a method in C# File.ReadAllLines . It reads all lines in

23TCP通信

匿名 (未验证) 提交于 2019-12-03 00:32:02
.pro 文件中加入:QT+=network 在Qt中实现TCP/IP服务器端通信的流程: 1.创建监听套接字,QTcpServer 2.将监听套接字设置为监听模式, listen 4.接收或者向客户端发送数据 5.接收数据:使用read()或者readAll()函数 6.发送数据:使用write()函数 监听套接字和通信套接字的区别: 在服务端包含两种套接字QTcpServer,QTcpSocket. QTcpServer用于listen()监听模式,监听哪个IP,从哪个端口接入。QTcpSocket用于两者之间的真正通信,当两者完成连接后,各个都拥有一个QTcpSocket,如:sock1,sock1,那么这两个通信套接字等同于各自的手机号码,用于通信使用。 客户端通信流程: 1.创建套接字 2.连接服务器,可以使用QTcpSocket类的connectToHost()函数来连接服务器。 3.向服务器发送或者接受数据 如图: 解析:当服务端处于监听模式时(listen),客户端通过connectToHost请求连接,此时服务端就是触发信号newConnection(系统给出,非自拟),调用对应的槽函数(可自拟,或直接使用Lambda表达式)。服务端连通后,客户端就会立即触发信号connected.说明两者之间已完成连接,彼此可以利用write发出信息,利用read