tcpclient

C# 网络编程之简易聊天示例

匿名 (未验证) 提交于 2019-12-02 22:09:29
还记得刚刚开始接触编程开发时,傻傻的将网站开发和网络编程混为一谈,常常因分不清楚而引为笑柄。后来勉强分清楚,又因为各种各样的协议端口之类的名词而倍感神秘,所以为了揭开网络编程的神秘面纱,本文尝试以一个简单的小例子,简述在网络编程开发中涉及到的相关知识点,仅供学习分享使用,如有不足之处,还请指正。 概述 在TCP/IP协议族中,传输层主要包括TCP和UDP两种通信协议,它们以不同的方式实现两台主机中的不同应用程序之间的数据传输,即数据的端到端传输。由于它们的实现方式不同,因此各有一套属于自己的端口号,且相互独立。采用五元组(协议,信源机IP地址,信源应用进程端口,信宿机IP地址,信宿应用进程端口)来描述两个应用进程之间的通信关联,这也是进行网络程序设计最基本的概念。传输控制协议(Transmission Control Protocol,TCP)提供一种面向连接的、可靠的数据传输服务,保证了端到端数据传输的可靠性。 涉及知识点 本例中涉及知识点如下所示: TcpClient : TcpClient类为TCP网络服务提供客户端连接,它构建于Socket类之上,以提供较高级别的TCP服务,提供了通过网络连接、发送和接收数据的简单方法。 TcpListener:构建于Socket之上,提供了更高抽象级别的TCP服务,使得程序员能更方便地编写服务器端应用程序。通常情况下

How to use Tor control protocol in C#?

自闭症网瘾萝莉.ら 提交于 2019-12-02 20:51:56
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 = MakeTcpRequest("SIGNAL NEWNYM\r\n", client); } client.Close(); return response; } public string

Stopping a TcpListener after calling BeginAcceptTcpClient

冷暖自知 提交于 2019-12-02 18:14:17
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()); listenerSocket.BeginAcceptTcpClient(new AsyncCallback(AcceptClient), null); } Now, I call BeginAcceptTcpClient,

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

旧街凉风 提交于 2019-12-02 17:28:54
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 to establish connection. I also tried by giving the command sqlcmd -S 127.0.0.1 -U SA -P '<YourPassword>

TcpClient vs Socket when dealing with asynchronousy

与世无争的帅哥 提交于 2019-12-02 16:44:09
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 using any of the communication protocols listed in the ProtocolType enumeration. To send/receive some

TCP read and write from client and server

无人久伴 提交于 2019-12-02 14:24:21
I'm trying to make a client and server which can read and write info back and forth between each other. I can write from the client and server reads it but not vise versa and I have no idea why. Nobody on here seems to know when I asked before and I cant find anything online that works. If you know please tell me and not tell me to go read an article about TCP because it doesn't help at all. Client: namespace ExampleClient { public partial class Form1 : Form { public static bool IsConnected; public static NetworkStream Writer; public static NetworkStream Receiver; public Form1() {

NetworkStream doesn't support seek operations

一曲冷凌霜 提交于 2019-12-02 12:35:25
问题 I'm creating simple proxy server but I faced a strange situation, I've following code : var clientRequestStream = _tcpClient.GetStream(); var requestHeader = clientRequestStream.GetUtf8String(); GetUtf8String is a extension method for Stream class which reads stream (contains HttpRequest headers). I need to extract those headers to access Host and Requested Url. Once reading NetworkStream is done. I need to perform seek operation and set its clientRequestStream.Position = 0; because I've to

Get the live data on TCP server from UWP (UPDATED)

落花浮王杯 提交于 2019-12-02 12:07:41
问题 Below is one method that basically sends the data to TCP Server. UPDATE BEGINS HERE: ////////////////////////////////// private string FormatValueByPresentation(IBuffer buffer, GattPresentationFormat format) { // BT_Code: For the purpose of this sample, this function converts only UInt32 and // UTF-8 buffers to readable text. It can be extended to support other formats if your app needs them. byte[] data; CryptographicBuffer.CopyToByteArray(buffer, out data); if (format != null) { if (format

Connection from linux to windows via tcp

只谈情不闲聊 提交于 2019-12-02 11:41:35
I have a tcp server application on windows (c#) wich accepts any connection by the port 3000 I have a tcp client application on linux(ubuntu)(c++) wich send a simple text by the port 3000 I also have a client on windows and a server on linux, i works perfectly sending the text: from linux to linux from windows to windows from windows to linux the problem is that when i try to send from linux client to windows server my c++ application on linux tells me that the host doesn't exist i already check the ip adress and it is correct i also tried to do it with hostname but it doesn't work does

C# - Socket to log on to Firewall

大兔子大兔子 提交于 2019-12-02 05:20:09
I wrote an app to automatically connect to our different Firewalls. All of them work with the same frontend. We telnet to the IP and they give the message LOGIN or LOGOUT and ask for a username or password. I used this code: public static void ConnectToFirewall(string strUsername, string strPassword, string strFirewallIp) { IPAddress[] ipaIpAddressCollection = Dns.GetHostAddresses(strFirewallIp); IPEndPoint ipeIpEndPoint = new IPEndPoint(ipaIpAddressCollection[0], intPort); Socket sckSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sckSocket.Connect