主题:一个网络编程的问题
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace socketclient
{
class Program
{
static void Main(string[] args)
{
Socket Client= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); //建立客户端套接字
IPAddress adr = IPAddress.Parse("127.0.0.1");
IPEndPoint ep = new IPEndPoint(adr, 3000);
Server.Connect(ep); //完成绑定
byte[] buffer = new byte[255];
String data = null;
int recv = 0;
recv = Server.Receive(buffer);
if (recv > 0)
{
Console.WriteLine("连接上...");
Console.WriteLine("从服务器接收数据...");
data = Encoding.ASCII.GetString(buffer, 0, recv);
Console.WriteLine(data);
while (true)
{
String input;
input = Console.ReadLine();
if (input == "exit")
{
break;
}
Server.Send(Encoding.ASCII.GetBytes(input));
}
Console.WriteLine("连接断开...");
Server.Shutdown(SocketShutdown.Both);
Server.Close();
}
}
}
}
在客户端的代码完成后运行出现了这样的问题,那位大虾来指点一下啊 我用的VS05
No connection could be made because the target machine actively refused it 127.0.0.1:3000
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace socketclient
{
class Program
{
static void Main(string[] args)
{
Socket Client= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); //建立客户端套接字
IPAddress adr = IPAddress.Parse("127.0.0.1");
IPEndPoint ep = new IPEndPoint(adr, 3000);
Server.Connect(ep); //完成绑定
byte[] buffer = new byte[255];
String data = null;
int recv = 0;
recv = Server.Receive(buffer);
if (recv > 0)
{
Console.WriteLine("连接上...");
Console.WriteLine("从服务器接收数据...");
data = Encoding.ASCII.GetString(buffer, 0, recv);
Console.WriteLine(data);
while (true)
{
String input;
input = Console.ReadLine();
if (input == "exit")
{
break;
}
Server.Send(Encoding.ASCII.GetBytes(input));
}
Console.WriteLine("连接断开...");
Server.Shutdown(SocketShutdown.Both);
Server.Close();
}
}
}
}
在客户端的代码完成后运行出现了这样的问题,那位大虾来指点一下啊 我用的VS05
No connection could be made because the target machine actively refused it 127.0.0.1:3000