實現TcpIp簡單傳送

?private void timer1_Tick(object sender, EventArgs e)
??????? {?????
?????????????? IPAddress ipstr = IPAddress.Parse("192.168.0.106");
?????????????? TcpListener? serverListener = new TcpListener(ipstr,13);//創建TcpListener對象實例
?????????????? serverListener.Start(); //啟動偵聽????
?????????????? TcpClient? tcpClient = serverListener.AcceptTcpClient();//創建客戶端連接對象
?????????????? NetworkStream netStream = tcpClient.GetStream();//得到網絡流
?????????????? StreamReader sr = new StreamReader(netStream);//流讀寫器??
??????????????? string received = "";
??????????????? received = sr.ReadLine();//讀流中一行
??????????????? this.label1.Text = "接收了" + received;
??????????????? if (received != "")
??????????????? {
??????????????????? timer1.Enabled = false;
??????????????? }
??????????????? sr.Close();
??????????????? netStream.Close();
??????????????? tcpClient.Close();
??????????????? serverListener.Stop();
??????? }


??????? public void SendMeg(string msg)//發送信息
??????? {
??????????? // int port = Int32.Parse(13);//遠程主機端口
??????????? TcpClient tcpClient = new TcpClient("192.168.0.106", 13);//創建TcpClient對象實例 }??????
??????????? string strDateLine = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();//得到發送時客戶端時間
??????????? NetworkStream netStream = tcpClient.GetStream();//得到網絡流
??????????? StreamWriter sw = new StreamWriter(netStream);//創建TextWriter,向流中寫字符
??????????? string words = msg;//待發送的話
??????????? string content = strDateLine + words;//待發送內容
??????????? sw.Write(content);//寫入流
??????????? sw.Close();//關閉流寫入器
??????????? netStream.Close();//關閉網絡流
??????????? tcpClient.Close();//關閉客戶端連接?
??????? }?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389208.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389208.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389208.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SQLServer之函數簡介

用戶定義函數定義 與編程語言中的函數類似,SQL Server 用戶定義函數是接受參數、執行操作(例如復雜計算)并將操作結果以值的形式返回的例程。 返回值可以是單個標量值或結果集。 用戶定義函數準則 在函數中,將會區別處理導致語句被…

無向圖g的鄰接矩陣一定是_矩陣是圖

無向圖g的鄰接矩陣一定是To study structure,tear away all flesh soonly the bone shows.要研究結構,請盡快撕掉骨頭上所有的肉。 Linear algebra. Graph theory. If you are a data scientist, you have encountered both of these fields in your study or work …

移動pc常用Meta標簽

移動常用 <meta charset"UTF-8"><title>{$configInfos[store_title]}</title><meta content"widthdevice-width,minimum-scale1.0,maximum-scale1.0,shrink-to-fitno,user-scalableno,minimal-ui" name"viewport"><m…

前端繪制繪制圖表_繪制我的文學風景

前端繪制繪制圖表Back when I was a kid, I used to read A LOT of books. Then, over the last couple of years, movies and TV series somehow stole the thunder, and with it, my attention. I did read a few odd books here and there, but not with the same ferocity …

Rapi

本頁內容 ●引言●SMARTPHONE SDK API 庫●管理設備中的目錄文件●取系統信息●遠程操作電話和短信功能 Windows Mobile日益成熟&#xff0c;開發者隊伍也越來越壯大。作為一個10年的計算機熱愛者和程序員&#xff0c;我也經受不住新技術的誘惑&#xff0c;倒騰起Mobile這個玩具…

android 字符串特殊字符轉義

XML轉義字符 以下為XML標志符的數字和字符串轉義符 " ( 或 &quot;) ( 或 &apos;) & ( 或 &amp;) lt(<) (< 或 <) gt(>) (> 或 >) 如題&#xff1a; 比如&#xff1a;在string.xml中定義如下一個字符串&#xff0c;…

如何描繪一個vue的項目_描繪了一個被忽視的幽默來源

如何描繪一個vue的項目Source)來源 ) Data visualization is a great way to celebrate our favorite pieces of art as well as reveal connections and ideas that were previously invisible. More importantly, it’s a fun way to connect things we love — visualizing …

數據存儲加密和傳輸加密_將時間存儲網絡應用于加密預測

數據存儲加密和傳輸加密I’m not going to string you along until the end, dear reader, and say “Didn’t achieve anything groundbreaking but thanks for reading ;)”.親愛的讀者&#xff0c;我不會一直待到最后&#xff0c;然后說&#xff1a; “沒有取得任何開創性的…

熊貓分發_熊貓新手:第一部分

熊貓分發For those just starting out in data science, the Python programming language is a pre-requisite to learning data science so if you aren’t familiar with Python go make yourself familiar and then come back here to start on Pandas.對于剛接觸數據科學的…

多線程 進度條 C# .net

前言  在我們應用程序開發過程中&#xff0c;經常會遇到一些問題&#xff0c;需要使用多線程技術來加以解決。本文就是通過幾個示例程序給大家講解一下多線程相關的一些主要問題。 執行長任務操作  許多種類的應用程序都需要長時間操作&#xff0c;比如&#xff1a;執行一…

window 10 多版本激活工具

window 10 通用版激活工具 云盤地址&#xff1a;https://pan.baidu.com/s/1bo3L4Kn 激活工具網站&#xff1a;http://www.tudoupe.com/win10/win10jihuo/2017/0516/6823.html 轉載于:https://www.cnblogs.com/ipyanthony/p/9288007.html

android 動畫總結筆記 一

終于有時間可以詳細去了解一下 android動畫&#xff0c;先從android動畫基礎著手。在android 3.0之前android動畫api主要是android.view.Animation包下的內容&#xff0c;來先看看這個包里面主要的類![Animation成員](https://img-blog.csdn.net/20150709115201928 "Anima…

《Linux內核原理與分析》第六周作業

課本&#xff1a;第五章 系統調用的三層機制&#xff08;下&#xff09; 中斷向量0x80和system_call中斷服務程序入口的關系 0x80對應著system_call中斷服務程序入口&#xff0c;在start_kernel函數中調用了trap_init函數&#xff0c;trap_init函數中調用了set_system_trap_gat…

使用C#調用外部Ping命令獲取網絡連接情況

使用C#調用外部Ping命令獲取網絡連接情況 以前在玩Windows 98的時候&#xff0c;幾臺電腦連起來&#xff0c;需要測試網絡連接是否正常&#xff0c;經常用的一個命令就是Ping.exe。感覺相當實用。 現在 .net為我們提供了強大的功能來調用外部工具&#xff0c;并通過重定向輸…

Codeforces Round 493

心情不好&#xff0c;被遣散回學校 &#xff0c;心態不好 &#xff0c;為什么會累&#xff0c;一直微笑就好了 #include<bits/stdc.h> using namespace std; int main() {freopen("in","r",stdin);\freopen("out","w",stdout);i…

android動畫筆記二

從android3.0&#xff0c;系統提供了一個新的動畫&#xff0d;property animation, 為什么系統會提供這樣一個全新的動畫包呢&#xff0c;先來看看之前的補間動畫都有什么缺陷吧1、傳統的補間動畫都是固定的編碼&#xff0c;功能是固定的&#xff0c;擴展難度大。比如傳統動畫只…

回歸分析檢驗_回歸分析

回歸分析檢驗Regression analysis is a reliable method in statistics to determine whether a certain variable is influenced by certain other(s). The great thing about regression is also that there could be multiple variables influencing the variable of intere…

是什么樣的騷操作讓應用上線節省90%的時間

優秀的程序員 總會想著 如何把花30分鐘才能解決的問題 在5分鐘內就解決完 例如在應用上線這件事上 通常的做法是 構建項目在本地用maven打包 每次需要clean一次&#xff0c;再build一次 部署包在本地ide、git/svn、maven/gradie 及代碼倉庫、鏡像倉庫和云平臺間 來回切換 上傳部…

QQ API

QQ API設計說明書目錄一、引言 31.1 編寫目的 31.2 更新時間 3二、總體設計 3三、注冊的系統消息 33.1 WM_QQAPI_REGISTER 33.2 WM_QQAPI_REGISTER_RESP 43.3 WM_QQAPI_AVAILABLE 4四、從設備到QQ的自定義事件 54.1 EVENT_QQAPI_SET_AUDIODEVICE …