none
关于c#功能用c++6.0实现的问题 RRS feed

  • 问题

  •  

    目前我正在开发这样一个程序,用silverlight实现实时接收数据,而发送端的程序是这样的,怎样用c++6.0 写出来?有人能贴出来吗?补充一下:是把c#代码如何用vc++6.0写出来 而不是转换为

      using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;
    using System.Timers;
    using System.Xml;
    using System.Reflection;
    using System.Threading;
    using System.Xml.Serialization;

    namespace SocketServices
    {
        public class ScoreSocketServer
        {
            TcpListener _Listener = null;
            Socket soc = null;
            static ManualResetEvent _TcpClientConnected = new ManualResetEvent(false);
            List<TcpClient> tcpClients = new List<TcpClient>();
            List<StreamWriter> _ClientStreams = new List<StreamWriter>();
        

            public void StartSocketServer()
            {

                    _Listener = new TcpListener(IPAddress.Any, 4530);
                    _Listener.Start();
                    Console.WriteLine("Server listening...");
                    while (true)
                    {
                        _TcpClientConnected.Reset();
                        Console.WriteLine("Waiting for client connection...");
                        _Listener.BeginAcceptTcpClient(new AsyncCallback(OnBeginAccept), null);
                        _TcpClientConnected.WaitOne(); //Block until client connects
                    }
          
            }

          
            private void OnBeginAccept(IAsyncResult ar)
            {
                this.DisposeClient();

                _TcpClientConnected.Set(); //Allow waiting thread to proceed
                TcpListener listener = _Listener;
                TcpClient client = listener.EndAcceptTcpClient(ar);
                this.tcpClients.Add(client);

                if (client.Connected)
                {
                    Console.WriteLine("Client connected...");
                    StreamWriter writer = new StreamWriter(client.GetStream());
                    writer.AutoFlush = true;
                    _ClientStreams.Add(writer);
                 
                }
            }


       


           

            public void StopSocketServer()
            {
                if (_ClientStreams != null && _ClientStreams.Count > 0)
                {
                    foreach (StreamWriter writer in _ClientStreams)
                    {
                        writer.Close();
                        writer.Dispose();
                    }
                    _ClientStreams.Clear();
                }
               
            }

        

            private void SendData(string data)
            {
                this.DisposeClient();

                if (_ClientStreams != null)
                {
                    foreach (StreamWriter writer in _ClientStreams)
                    {
                        if (writer != null)
                        {
                            writer.Write(data);
                        }
                    }
                }
              
            }

            private string GetOnceData()
            {
                return new Random().Next(0, 9999).ToString();
            }

            private string GetData()
            {
                Thread.Sleep(100);
                return this.imagesName[new Random().Next(1, 8)];
            }

          
        }
    }

    2008年11月1日 5:31

答案

  • 你的意思是要用VC6编译上面那段C#代码吗?直接用VC6可能无法实现~你可以用C#编译器(csc.exe)去编译~

    2008年11月1日 12:56
    版主

全部回复