-
大小: 5.11MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-11-17
- 语言: 其他
- 标签: SuperSocket Socket c#Socket
资源简介
socket服务端采用SuperSocket搭建,客户端与服务端进行连接及向服务端发送消息,服务端使用业务向客户端发送消息进行通信
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace superSocketClient
{
class Program
{
static Socket socketClient { get; set; }
static void Main(string[] args)
{
//创建实例
socketClient = new Socket(SocketType.Stream ProtocolType.Tcp);
IPAddress ip = IPAddress.Parse(“127.0.0.1“);
IPEndPoint point = new IPEndPoint(ip 2018);
try
{
//进行连接
socketClient.Connect(point);
//不停的接收服务器端发送的消息
Thread thread = new Thread(Recive);
thread.IsBackground = true;
thread.Start();
////不停的给服务器发送数据
Thread thread2 = new Thread(Send);
thread2.IsBackground = true;
thread2.Start();
}
catch (Exception ex)
{
Console.WriteLine(“连接服务器失败 --- “ + ex.Message);
}
Console.ReadKey();
}
///
/// 接收消息
///
///
static void Recive()
{
// 为什么用telnet客户端可以,但这个就不行。
while (true)
{
//获取发送过来的消息
byte[] buffer = new byte[1024 * 1024 * 2];
var effective = socketClient.Receive(buffer);
if (effective == 0)
{
break;
}
var str = Encoding.UTF8.GetString(buffer 0 effective);
Console.WriteLine(“来自服务器 --- “ + str);
Thread.Sleep(1000);
}
}
static void Send()
{
int i = 0;
//SignResult
var sendStr = “SignResult 15023399108 \r\n“;
var buffter = Encoding.UTF8.GetBytes(sendStr);
var temp = socketClient.Send(buffter);
Console.WriteLine(sendStr);
//ADD
sendStr = “ADD 1 2 \r\n“;
buffter = Encoding.UTF8.GetBytes(sendStr);
temp = socketClient.Send(buffter);
Console.WriteLine(sendStr);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-08-18 10:54 superSocketServer\
目录 0 2018-08-17 17:22 superSocketServer\.vs\
目录 0 2018-08-17 17:22 superSocketServer\.vs\superSocketServer\
目录 0 2018-08-17 17:22 superSocketServer\.vs\superSocketServer\v14\
文件 52736 2018-08-18 12:32 superSocketServer\.vs\superSocketServer\v14\.suo
目录 0 2018-08-17 17:32 superSocketServer\packages\
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\net10-full\
文件 299008 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net10-full\log4net.dll
文件 1432719 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net10-full\log4net.xm
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\net11-full\
文件 299008 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net11-full\log4net.dll
文件 1433870 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net11-full\log4net.xm
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\net20-full\
文件 303104 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net20-full\log4net.dll
文件 1452231 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net20-full\log4net.xm
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\net35-client\
文件 307200 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net35-client\log4net.dll
文件 1506806 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net35-client\log4net.xm
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\net35-full\
文件 311296 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net35-full\log4net.dll
文件 1517265 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net35-full\log4net.xm
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\net40-client\
文件 299520 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net40-client\log4net.dll
文件 1506806 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net40-client\log4net.xm
目录 0 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\lib\net40-full\
文件 301056 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net40-full\log4net.dll
文件 1517265 2013-11-23 10:04 superSocketServer\packages\log4net.2.0.3\lib\net40-full\log4net.xm
文件 1931465 2018-08-17 17:23 superSocketServer\packages\log4net.2.0.3\log4net.2.0.3.nupkg
目录 0 2018-08-17 17:23 superSocketServer\packages\SuperSocket.1.6.6.1\
............此处省略117个文件信息
相关资源
- 网络编程socket文件图片等传送
- tomcat7.0.42 下部署websocket需要替换的包
- 安卓手机socket通信服务端和客户端
- 物联网,WEBSOCKET丰富案例
- nodejs聊天室
- websocket简单web项目,直接部署可使用
- Windows与Linux之间使用socket进行文件传
- 基于SOCKECT的TCP的通信
- Socket实现一对一聊天
- 基于Socket的局域网即时通信系统的开
- 高德地图+websocket
- libwebsockets-v1.6-stable.tar.gz
- HololensSocketDemo.rar
- socket传输16进制客户端
- 基于Win socket简单实现一个FTP协议的客
- 基于socket的简易多人聊天室
- webRTC+socketio+SpringBoot视频及文字聊天
- okSocket库的使用
- Linux网络编程-网络基础-socket编程-高并
- 用TCP/socket实现windows与linux通信文件传
- SocketTool4.zip
- weblogic websocket
- websocket
- SuperSocket1.6中文文档PDF版
- 基于spring websocket实现广播及点对点推
- SuperSocket_demo
- 手机采集摄像头视频socket实时传播 由
- tomcat实现websocket聊天室
- G-Sockets 2.5
- TCP文件传输Demo
评论
共有 条评论