1
我有两个进程Client和Server。 这是因为follws: 这是我的客户的过程: -使用tcp在同一台机器上的进程间通信
[Serializable ]
public class retobj
{
public int a;
}
class client
{
static void Main(string[] args)
{
TcpClient client = new TcpClient();
client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5005));
Console.WriteLine("Connected.");
retobj ob = new retobj();
ob.a = 90;
BinaryFormatter bf = new BinaryFormatter();
NetworkStream ns = client.GetStream();
bf.Serialize(ns, ob);
Console.WriteLine("Data sent.");
Console.ReadLine();
ns.Close();
client.Close();
}
}
这是我的服务器进程:
[Serializable]
public class retobj
{
public int a;
}
class server
{
static void Main(string[] args)
{
TcpListener listener = new TcpListener(IPAddress.Any, 5005);
listener.Start();
Console.WriteLine("Server started.");
Socket client = listener.AcceptSocket();
Console.WriteLine("Accepted client {0}.\n", client.RemoteEndPoint);
List<string> l = null;
retobj j = null;
using (NetworkStream ns = new NetworkStream(client))
{
BinaryFormatter bf = new BinaryFormatter();
j = (retobj)bf.Deserialize(ns);
}
//if (l != null)
// foreach (var item in l)
// Console.WriteLine(item);
Console.WriteLine(j.a);
Console.ReadLine();
client.Close();
listener.Stop();
}
但它给像一个错误:在服务器进程 错误: 无法找到程序集'ConsoleApplication45,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'。
非常Thanx兄弟真棒解决方案... – yuthub