123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading.Tasks;
- namespace Srez
- {
- public class WsClient
- {
- private static byte[] bytes = new byte[1024];
- private static IPHostEntry iPHostEntry = Dns.GetHostEntry("localhost");
- private static IPAddress iPAddress = iPHostEntry.AddressList[0];
- private static IPEndPoint iPEndPoint = new IPEndPoint(iPAddress, 11000);
- private static Socket socket = null;
- public static void WsClientConnect()
- {
- socket = new Socket(iPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
- socket.Connect(iPEndPoint);
- }
- public static void WsClientSendMessage(string data)
- {
- socket.Send(Encoding.UTF8.GetBytes(data));
- }
- public static string WsClientResponseFromWss()
- {
- return Encoding.UTF8.GetString(bytes, 0, socket.Receive(bytes));
- }
- public static void WsClientClose()
- {
- socket.Shutdown(SocketShutdown.Both);
- socket.Close();
- }
- }
- }
|