using System; using System.Collections.Generic; using System.Linq; using System.Net.Sockets; using System.Text; namespace SocketConnection { public class Socket1 { //连接服务器端 #region 连接服务器端 public static Socket ConnectServer(string ip, int port) { Socket socket = null; try { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ip, port); } catch (Exception ex) { } return socket; } #endregion //给端,发送消息的封装 #region 给端,发送消息的封装 public static bool SendData(Socket socket, byte[] data) { socket.Send(data, 0, data.Length, 0); return true; } #endregion } }