求C#聊天室源代码

C#聊天室源代码,要求有后台源代码,急!!!不好意思,没多少分数,全给了邮箱cathykakaxi@163.com... C#聊天室源代码,要求有后台源代码,急!!!不好意思,没多少分数,全给了
邮箱cathykakaxi@163.com
展开
 我来答
chenliangbdu
2009-10-08 · TA获得超过115个赞
知道小有建树答主
回答量:135
采纳率:0%
帮助的人:97.2万
展开全部
给个邮箱地址,发给你
果敢还敦厚灬百花8713
2009-10-12 · 超过29用户采纳过TA的回答
知道答主
回答量:112
采纳率:0%
帮助的人:78.8万
展开全部
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace UdpServer
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Char
{
private static IPAddress remoteIPAddress;
private static int remotePort;
private static int localPort;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
//Get necessary data for connection
Console.WriteLine("Enter Local port");
localPort = Convert.ToInt16(Console.ReadLine());

Console.WriteLine("Enter remote port");
remotePort = Convert.ToInt16(Console.ReadLine());

Console.WriteLine("Enter remote IP Address");
remoteIPAddress = IPAddress.Parse(Console.ReadLine());

//Create thread for listening
Thread tRec = new Thread(new ThreadStart(Receiver));
tRec.Start();

while(true)
{
Send(Console.ReadLine());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

private static void Send(string datagram)
{
//Create UdpClient
UdpClient sender = new UdpClient();

//Create IPEndPoint with detail of remote host
IPEndPoint endPoint = new IPEndPoint(remoteIPAddress,remotePort);

try
{
byte[] bytes = Encoding.ASCII.GetBytes(datagram);
sender.Send(bytes,bytes.Length,endPoint);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
sender.Close();
}
}

private static void Receiver()
{
//Create a UdpClient for reading incoming data.
UdpClient receivingUdpClient = new UdpClient(localPort);

//IPEndPoint with remote host information
IPEndPoint RemoteIPEndPoint = null;

try
{
Console.WriteLine("---------------*********Ready for char!!!!*******------------");
while(true)
{
//wait for datagram
byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIPEndPoint);

//Convert and display data
string returndata = Encoding.ASCII.GetString(receiveBytes);
Console.WriteLine("-"+returndata.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式