谁能给一基本client server in C# 程序 可以通话就成 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 socket通话参考 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 Server = 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(); } } }}using System;using System.Collections.Generic;using System.Text;using System.Net;using System.Net.Sockets;namespace socketserver{ class Program { static void Main(string[] args) { Socket client; int recv; //byte[] message = new byte[1024]; Socket ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); IPAddress adr = IPAddress.Parse("127.0.0.1"); IPEndPoint ep = new IPEndPoint(adr, 3000); ServerSocket.Bind(ep); //类似于客户机的connect()方法 ServerSocket.Listen(3); //开始监听 while (true) { if ((client = ServerSocket.Accept()) != null) { Console.WriteLine("连接上...发送数据...."); //欲发送的字节数组,以0为结束标记 byte[] message = { 10, 20, 30, 40, 50, 60, 0 }; //send方法返回发送的字节数 Console.WriteLine("总计将发送" + client.Send(message) + "个字节的数据"); Console.WriteLine("结束."); client.Close(); break; } } } }} 要先能通话 然后建立 desktop TCPIP remote control ......需要用到System.MarshalByRefObject不 dataTimepicker控件值作为查询数据库条件格式~~~ ie8 调试缺少对象 1-100个数,不重复的随机插入到维数为99的数组,请用最有高效的方法查出这100个数中那一个数是没有插入到数组中的? C# Load Library Dll问题 关于AutoCompleteMode的自动完成功能 分都给光了。唉 问个问题缩略图生成。。!! HttpClient用异步委托和线程池报错问题 请问怎么把XLS,PPT等OFFICE文档转换为TXT? 请教C#的入门书籍? C#问题 C#找不到水晶报表控件 C# 自定义属性的问题?
参考
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 Server = 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();
}
}
}
}using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;namespace socketserver
{
class Program
{
static void Main(string[] args)
{
Socket client;
int recv;
//byte[] message = new byte[1024];
Socket ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
IPAddress adr = IPAddress.Parse("127.0.0.1");
IPEndPoint ep = new IPEndPoint(adr, 3000); ServerSocket.Bind(ep); //类似于客户机的connect()方法
ServerSocket.Listen(3); //开始监听 while (true)
{
if ((client = ServerSocket.Accept()) != null)
{
Console.WriteLine("连接上...发送数据....");
//欲发送的字节数组,以0为结束标记 byte[] message = { 10, 20, 30, 40, 50, 60, 0 };
//send方法返回发送的字节数
Console.WriteLine("总计将发送" + client.Send(message) + "个字节的数据");
Console.WriteLine("结束.");
client.Close();
break;
}
}
}
}
}
需要用到System.MarshalByRefObject不