Server:

using System.Net;
using System.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ServerConsole
{
class Server
{
static void Main(string[] args)
{
Console.WriteLine("Server is runing...");
IPAddress ip = new IPAddress(new byte[]{,,,});
TcpListener listener = new TcpListener(ip, ); listener.Start();//开始侦听
while (true)
{
//获取一个连接,中断方法
TcpClient remoteClient = listener.AcceptTcpClient();
//打印连接客户端的信息
Console.WriteLine("Client Connected!{0}---->{1}", remoteClient.Client.LocalEndPoint,remoteClient.Client.RemoteEndPoint);
}
}
}
}

Client:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets; namespace ClientConsole
{
class Client
{
static void Main(string[] args)
{
Console.WriteLine("Client is running...");
TcpClient client = null; for (int i = ; i < ; i++)
{
client = new TcpClient();
try
{
//与服务器建立连接
client.Connect("localhost", ); ;
}
catch (Exception ex)
{
Console.WriteLine("Exception occured.." + ex.Message);
return;
} //输出已连接到服务器
Console.WriteLine("Server Connected!{0}-->{1}",
client.Client.LocalEndPoint, client.Client.RemoteEndPoint);
}
ConsoleKey key;
do
{
key = Console.ReadKey(true).Key;
} while (key != ConsoleKey.Q);
}
}
}

C#网络通信的更多相关文章

  1. ZeroMQ实例-使用ZMQ(ZeroMQ)进行局域网内网络通信

    本文内容摘要:1)安装zeromq.2)实例说明使用zmq进行网络间的消息发送和接收 首先在机器中安装zmq库 步骤如下: 1)下载zeromq的源代码,ZeroMQ的官方网址:http://zero ...

  2. 基础笔记12(socket,url网络通信)

    进一步深入socket 1.网络通信条件: .IP地址,可用主机名. .传输数据时将不用的应用程序通过数字标识区分开来,这种标识称为逻辑端口,也称端口.(0-65535端口,一般系统预留0-1024) ...

  3. Windows Store App 网络通信 HttpWebRequest

    如果希望更好地控制HTTP请求,可以使用System.Net类库中的HttpWebRequest类,该类对HTTP协议进行了完整的封装,并且提供了很多对HTTP协议中的 Header.Content和 ...

  4. socket网络通信

    1.socket通常也称作"套接字",用于描述IP地址和端口.在internet上的主机一般运行了多个服务软件,同时提供几种服务,每种服务都打开一个socket,并绑定到一个端口上 ...

  5. 20145316&20145229实验五:网络通信

    20145316&20145229实验五:网络通信 结对伙伴:20145316 博客链接:http://www.cnblogs.com/xxy745214935/p/6130897.html

  6. 网络通信之Socket与LocalSocket的比较

    Socket与LocalSocket都可以实现网络通信,两个有什么区别呢? LocalSocket其通信方式与Socket差不多,只是LocalSocket没有跨越网络边界. 于是,思考到一个问题:a ...

  7. Android 网络通信API的选择和实现实例

    Android开发网络通信一开始的时候使用的是AsyncTask封装HttpClient,没有使用原生的HttpURLConnection就跳到了Volley,随着OkHttp的流行又开始迁移到OkH ...

  8. java 25 - 2 网络编程之 网络通信三要素

    网络通信三要素 IP地址: InetAddress 网络中设备的标识,不易记忆,可用主机名(计算机的标识号) 端口号: 用于标识进程的逻辑地址,不同进程的标识(正在运行的软件的标识号) 传输协议: 通 ...

  9. TCP/UDP,SOCKET网络通信,C++/Java实现

    趁这两天没事干,就把网络通信这一块搞一搞,C/S方面的了解一下,很重要! TCP Server/Client

  10. Java网络通信初步认知

    本文转载自:http://wing011203.cnblogs.com/ 在这篇文章里,我们主要讨论如何使用Java实现网络通信,包括TCP通信.UDP通信.多播以及NIO. TCP连接 TCP的基础 ...

随机推荐

  1. Helpers\TableBuilder

    Helpers\TableBuilder Table builder helper is a class that would help you to create tables in MySQL ( ...

  2. debian root用户在shell下如何能够使用颜色

    转载:http://hi.baidu.com/aivera/item/f31c4a590ef72609e6c4a596 编辑 /root/.bashrc 这个文件, 把里面这几行前面的#号去掉就可以了 ...

  3. centos 配置NFS服务器

    转载:http://boloveyo.blog.163.com/blog/static/203926187201232383956558/ 系统是CentOS5.6,假设NFS Server IP为1 ...

  4. iOS 开发常用宏

    来源:iOS_小松哥 链接:http://www.jianshu.com/p/be00c3f3cafd 大家都是知道使用宏不仅方便,而且可以提高开发效率.下面总结了iOS开发过程中的一些常用宏,会持续 ...

  5. JavaScript 正则表达式相关理解

    1.使用正则的test.exec方法而且带有g属性进行连续匹配的时候, 如果每次匹配之前 lastIndex属性没有清零. <script> var str='123qweQWE125|2 ...

  6. linux mail 配置

    1:sudo apt-get install sendmail sendmail-cf2:ps aux | grep sendmail3.配置/etc/mail/sendmail.mc    FEAT ...

  7. LeetCode 42

    Trapping Rain Water Given n non-negative integers representing an elevation map where the width of e ...

  8. Scala中的元组

    元组 元组使用()表示的数据结构 元组使用()表示的数据结构 还可以使用模式匹配访问 使用场景非常有限,用于函数返回值不止1个的情况下 看代码: /** * 元组 * @author Administ ...

  9. MapReduce在Map端的Combiner和在Reduce端的Partitioner

    1.Map端的Combiner. 通过单词计数WordCountApp.java的例子,如何在Map端设置Combiner... 只附录部分代码: /** * 以文本 * hello you * he ...

  10. 【dp入门题】【跟着14练dp吧...囧】

    A HDU_2048 数塔 dp入门题——数塔问题:求路径的最大和: 状态方程: dp[i][j] = max(dp[i+1][j], dp[i+1][j+1])+a[i][j];dp[n][j] = ...