将套接字从 C# 传递到 NetFoss
NetFoss 要求您使用类似于以下的命令行运行它:
nf.bat /n[#] /h[#] [命令行] 其中 /n[#] 是节点号,/h[#] 是操作系统套接字句柄。
我想用 C# 编写一些非常类似于 telnet BBS 在运行门游戏时所做的事情。它应该接受客户端套接字,收集从客户端传递到其中的一些信息,然后将套接字传递给 NetFoss 以用于运行基于 DOS 的应用程序,该应用程序支持通过化石驱动程序进行通信。
老实说,我只是猜测如何解决这个问题,这就是我想到的:
class Program
{
const int BACKLOG_SIZE = 20;
static void Main(string[] args)
{
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
server.Bind(new IPEndPoint(IPAddress.Any, 3102));
server.Listen(BACKLOG_SIZE);
while (true)
{
Socket socket = server.Accept();
Process p = new Process();
p.EnableRaisingEvents = false;
p.StartInfo.FileName = @"c:\netfoss\nf.bat";
p.StartInfo.Arguments = @"/n1 /h" + socket.Handle + @" c:\game\game.bat 1";
p.StartInfo.WorkingDirectory = "c:\netfoss";
p.StartInfo.UseShellExecute = false;
p.Start();
}
}
}
有趣的是,NetFoss 通过 game.bat 运行的应用程序被输出到 C# 应用程序的控制台窗口,而不是 telnet 客户端,甚至更有趣的是,telnet 客户端确实收到了初始 NetFoss 消息,表明它能够与套接字进行通信。那么,为什么传递到 NetFoss 的应用程序输出到我的控制台窗口而不是 telnet 客户端?
有人知道我错过了什么吗?
编辑:
我忘了提及,我还尝试将 UseShellExecute 设置为 TRUE,这会引发 NetFoss 错误,指出它是无效句柄。根据我的理解,我必须以某种方式复制句柄,以便非托管应用程序可以访问它?有什么办法可以使用 C# 来完成我想要做的事情吗?
谢谢, 马克
NetFoss requires you to run it with a command line similar to this:
nf.bat /n[#] /h[#] [command line]
where /n[#] is a node number and /h[#] is an OS socket handle.
I want to write something in C# very similar to what a telnet BBS would do when it runs door games. It should accept the client socket, gather a bit of information passed into it from the client, then pass the socket over to NetFoss to be used to run a DOS based application that supports communications via a fossil driver.
I honestly was just guessing about how to go about this, and here's what I came up with:
class Program
{
const int BACKLOG_SIZE = 20;
static void Main(string[] args)
{
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
server.Bind(new IPEndPoint(IPAddress.Any, 3102));
server.Listen(BACKLOG_SIZE);
while (true)
{
Socket socket = server.Accept();
Process p = new Process();
p.EnableRaisingEvents = false;
p.StartInfo.FileName = @"c:\netfoss\nf.bat";
p.StartInfo.Arguments = @"/n1 /h" + socket.Handle + @" c:\game\game.bat 1";
p.StartInfo.WorkingDirectory = "c:\netfoss";
p.StartInfo.UseShellExecute = false;
p.Start();
}
}
}
Interestingly enough, the application that NetFoss is running via game.bat is being output to the C# application's console window but not the telnet client, and even more interesting is that the telnet client DOES receive the initial NetFoss message that shows it is able to communicate with the socket. So, why is the application that is passed to NetFoss outputting to my console window instead of the telnet client?
Anyone know what I'm missing?
EDIT:
I forgot to mention that I also tried setting UseShellExecute to TRUE, and this throws a NetFoss error saying that it is an invalid handle. From my understanding, I would have to duplicate the handle in some way so that the unmanaged application can access it? Is there any way to accomplish what I'm trying to do using C#?
Thanks,
Marc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DOS 应用程序输出到控制台窗口是正常的,但它也应该输出到 telnet 客户端。
由于您在 telnet 客户端中看到初始 NetFoss 版本消息,我们知道套接字句柄已成功传递给 NetFoss...所以听起来问题在于您的 DOS 应用程序不支持 FOSSIL,或者当前尚未配置使用 FOSSIL 或 INT14h 通信方法。
问候,迈克
NetFoss开发者
It is normal that the DOS application outputs to your console window, but it should also output to the telnet client.
Since you are seeing the initial NetFoss version message in your telnet client, we know that the socket handle is being sucesfully passed to NetFoss... So it sounds like the problem is that your DOS application is not FOSSIL aware, or is not currently configured to use a FOSSIL or an INT14h communications method.
Regards, Mike
NetFoss developer