C#网络通信
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#网络通信的更多相关文章
- ZeroMQ实例-使用ZMQ(ZeroMQ)进行局域网内网络通信
本文内容摘要:1)安装zeromq.2)实例说明使用zmq进行网络间的消息发送和接收 首先在机器中安装zmq库 步骤如下: 1)下载zeromq的源代码,ZeroMQ的官方网址:http://zero ...
- 基础笔记12(socket,url网络通信)
进一步深入socket 1.网络通信条件: .IP地址,可用主机名. .传输数据时将不用的应用程序通过数字标识区分开来,这种标识称为逻辑端口,也称端口.(0-65535端口,一般系统预留0-1024) ...
- Windows Store App 网络通信 HttpWebRequest
如果希望更好地控制HTTP请求,可以使用System.Net类库中的HttpWebRequest类,该类对HTTP协议进行了完整的封装,并且提供了很多对HTTP协议中的 Header.Content和 ...
- socket网络通信
1.socket通常也称作"套接字",用于描述IP地址和端口.在internet上的主机一般运行了多个服务软件,同时提供几种服务,每种服务都打开一个socket,并绑定到一个端口上 ...
- 20145316&20145229实验五:网络通信
20145316&20145229实验五:网络通信 结对伙伴:20145316 博客链接:http://www.cnblogs.com/xxy745214935/p/6130897.html
- 网络通信之Socket与LocalSocket的比较
Socket与LocalSocket都可以实现网络通信,两个有什么区别呢? LocalSocket其通信方式与Socket差不多,只是LocalSocket没有跨越网络边界. 于是,思考到一个问题:a ...
- Android 网络通信API的选择和实现实例
Android开发网络通信一开始的时候使用的是AsyncTask封装HttpClient,没有使用原生的HttpURLConnection就跳到了Volley,随着OkHttp的流行又开始迁移到OkH ...
- java 25 - 2 网络编程之 网络通信三要素
网络通信三要素 IP地址: InetAddress 网络中设备的标识,不易记忆,可用主机名(计算机的标识号) 端口号: 用于标识进程的逻辑地址,不同进程的标识(正在运行的软件的标识号) 传输协议: 通 ...
- TCP/UDP,SOCKET网络通信,C++/Java实现
趁这两天没事干,就把网络通信这一块搞一搞,C/S方面的了解一下,很重要! TCP Server/Client
- Java网络通信初步认知
本文转载自:http://wing011203.cnblogs.com/ 在这篇文章里,我们主要讨论如何使用Java实现网络通信,包括TCP通信.UDP通信.多播以及NIO. TCP连接 TCP的基础 ...
随机推荐
- Linux shell 脚本攻略之统计文件的行数、单词数和字符数
摘自:<Linux shell 脚本攻略>
- Centos 安装KScope1.6.2
准备工作:安装ctags graphviz,和cscope (可以用yum install来安装) 1.首先下载kscope,最好下载16.x的版本,这个最好的 下载kscope-1.6.2.tar ...
- oracle 自增列设置
序列 create sequence sq_1 minvalue maxvalue start increment cache ; 触发器 create or replace trigger 触发器名 ...
- linux的cron服务及应用
Linux下的Cron用于定时执行设置的周期性指令,是Linux的内置服务,可以用以下的方法启动.关闭这个服务: /sbin/service crond start //启动服务 /sbin/serv ...
- Adobe Edge Animate –使用css制作菜单
Adobe Edge Animate –使用css制作菜单 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 效果图:
- MySQL中的保留字
本文转载自:http://www.cnblogs.com/lawdong/archive/2010/08/08/2357903.html ADD ALL ALTER ANALYZE AND AS AS ...
- 【置换,推理】UVa 1315 - Creaz tea party
Dsecription n participants of «crazy tea party» sit around the table. Each minute one pair of neighb ...
- ClassLoader类加载器
总的来说,当动态加载一个资源时,至少有三种类加载器可供选择: 系统类加载器(也被称为应用类加载器)(system classloader) 当前类加载器(current classloader) 当前 ...
- Netty线程模型
一.Reactor模型 1.单线程模型 Reactor单线程模型,指的是所有的IO操作都在同一个NIO线程上面完成,NIO线程的职责如下: 1)作为NIO服务端,接收客户端的TCP连接: 2)作为NI ...
- 使用迭代器遍历List的时候修改List报ConcurrentModificationException异常的解决办法
为了避免这种异常,我们可以使用CopyOnWriteArrayList来代替ArrayList,CopyOnWriteArrayList支持并发访问,所以同时进行迭代和修改是没有问题的.