int port=2000; string host="127.0.0.1"; IPAddress ip = IPAddress.Parse(host); IPEndPoint ipe = new IPEndPoint(ip,port);//把ip和端口转化为IPEndPoint实例 Socket c = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);//创建一个Socket c.Connect(ipe);//连接到服务器 string sendStr = "hello!This is a socket test"; byte[] bs = Encoding.ASCII.GetBytes(sendStr); c.Send(bs,bs.Length,0);//发送测试信息 c.Close(); 这个好像可以实现,但是我需要UCP多线程发送,该如何改写
windows下不需要fork进程来处理,用线程来处理就可以了
在界面上弄2个编辑框,一个按钮,2个编辑框分别关联上CString和int变量,
然后在按钮响应函数里,
UpdateData(TRUE);
//然后使用这2个变量
if (i==验证器连接的时候)
{
while(i==true)
send(连接);
}
else
{
while(i==true)
send(断开);
}}
但是写不出来
string host="127.0.0.1";
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip,port);//把ip和端口转化为IPEndPoint实例
Socket c = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);//创建一个Socket
c.Connect(ipe);//连接到服务器
string sendStr = "hello!This is a socket test";
byte[] bs = Encoding.ASCII.GetBytes(sendStr);
c.Send(bs,bs.Length,0);//发送测试信息
c.Close(); 这个好像可以实现,但是我需要UCP多线程发送,该如何改写