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. cocos2d-x lua 实现状态机

    cocos2d-x lua 实现状态机 version: cocos2d-x 3.6 0.状态机 状态机主要分为2大类:第一类,若输出只和状态有关而与输入无关,则称为Moore状态机:第二类,输出不仅 ...

  2. U盘安装Debian 7

    网上看到好多使用U盘安装的教程,齐说不一.实践是检验真理的标准,Try it ! 下载系统镜像:http://cdimage.debian.org/cdimage/release/current/am ...

  3. [OM]Dropship SO(直发/直运订单)的流程

    What are the advantages of Drop Shipment Orders? These are the benefits: No inventory is required Re ...

  4. [改善Java代码]多种最值算法,适时选择

    建议64:多种最值算法,适时选择. 对一批数据进行排序,然后找出其中的最大值或最小值,这是基本的数据结构知识.在Java中我们可以通过编写算法的方式,也可以通过数组先排序再取值的方式来实现.下面以求最 ...

  5. 转:OpenResty最佳实践(推荐了解lua语法)

    看点: 1. Lua 语法的说明, 排版清晰易懂. 转: https://moonbingbing.gitbooks.io/openresty-best-practices/content/lua/m ...

  6. Nginx - Rewrite Module

    Initially, the purpose of this module (as the name suggests) is to perform URL rewriting. This mecha ...

  7. 【AngularJs】---实现select的ng-options

    controller .controller('MainController', function($scope, $http, $ionicModal, $timeout) { var post = ...

  8. Java Servlet-入门

    配置 servlet <servlet> <servlet-name>one</servlet-name> <servlet-class>servlet ...

  9. namenode无法启动(namenode格式化失败)

    格式化namenode root@node04 bin]# sudo -u hdfs hdfs namenode –format 16/11/14 10:56:51 INFO namenode.Nam ...

  10. win10下怎么在桌面创建IIS快捷方式

    在电脑上打开C:\Windows\System32\inetsrv,在里面找到InetMgr.exe,如图 2 右击InetMgr.exe会发现没有发送到桌面的选项,所以我们选择创建快捷方式,如图 3 ...