1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ant.Service.Utility
- {
- public class SocketClient : Object
- {
- private TcpClient tcpClient;
- public SocketClient()
- {
- tcpClient = new TcpClient();
- tcpClient.Client.Blocking = true;
- }
-
-
-
-
-
- public void Connect(string host, int port)
- {
- tcpClient.Connect(host, port);
- }
-
-
-
- public void Disconnect()
- {
- tcpClient.Close();
- }
-
-
-
-
-
- public bool SendData(byte[] buffer)
- {
- var len = tcpClient.Client.Send(buffer, 0, buffer.Length, SocketFlags.None);
- return len > 0;
- }
- }
- }
|