【发布时间】:2015-01-02 00:20:52
【问题描述】:
我的客户端无法连接到我尝试连接的 irc 服务器。我做了一些研究,它说我需要监听端口 113 并以某种格式响应服务器。我不确定该怎么做。当我在收到错误消息之前尝试这样做时。这是我尝试收听之前的代码。 irc 将消息发送给我的客户“没有身份响应”。我是否需要一起创建一个完全不同的东西来监听端口 113 上的响应,或者我可以在这里做吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace ConnectIRC
{
class Program
{
static void Main(string[] args)
{
string ip = "asimov.freenode.net";
string nick = " NICK IKESBOT \r\n";
string join = "JOIN #NetChat\r\n";
int port = 6667;
const int recvBufSize = 8162;
byte[] recvbBuf = new byte[recvBufSize];
//stores the nick
byte[] nickBuf = Encoding.ASCII.GetBytes(nick);
//Stores the room join
byte[] joinBuf = Encoding.ASCII.GetBytes(join);
Socket conn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
conn.Connect(ip, port);
conn.Send(nickBuf, nickBuf.Length, SocketFlags.None);
conn.Send(joinBuf, joinBuf.Length, SocketFlags.None);
for(;;){
byte[] buffer = new byte[3000];
int rec = conn.Receive(buffer, 0, buffer.Length, 0);
Array.Resize(ref buffer, rec);
Console.WriteLine(Encoding.Default.GetString(buffer));
}
}
}
}
【问题讨论】:
标签: c# client protocols server irc