Пример #1
0
        public static int accept0(object _this, FileDescriptor ssfd, FileDescriptor newfd, object isaa)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                System.Net.Sockets.Socket netSocket = ssfd.getSocket();
                if (netSocket.Blocking || netSocket.Poll(0, System.Net.Sockets.SelectMode.SelectRead))
                {
                    System.Net.Sockets.Socket accsock = netSocket.Accept();
                    newfd.setSocket(accsock);
                    System.Net.IPEndPoint ep = (System.Net.IPEndPoint)accsock.RemoteEndPoint;
                    ((global::java.net.InetSocketAddress[])isaa)[0] = new global::java.net.InetSocketAddress(global::java.net.SocketUtil.getInetAddressFromIPEndPoint(ep), ep.Port);
                    return(1);
                }
                else
                {
                    return(global::sun.nio.ch.IOStatus.UNAVAILABLE);
                }
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
Пример #2
0
        internal static string UnixSocketServerCreate_CORRECT_NO_HACK(VmContext vm, object[] serverOut, string path, Value onRecvCb)
        {
            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(
                System.Net.Sockets.AddressFamily.Unix,
                System.Net.Sockets.SocketType.Stream,
                System.Net.Sockets.ProtocolType.Unspecified);
            serverOut[0] = socket;
            socket.Bind(new System.Net.Sockets.UnixDomainSocketEndPoint(path));
            socket.Listen(1); // TODO: customizable value
            System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();

            bgworker.DoWork += (e, sender) =>
            {
                System.Net.Sockets.Socket s = socket.Accept();
                byte[] buffer    = new byte[2048];
                int    bytesRead = 0;
                do
                {
                    bytesRead = s.Receive(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None);
                    // TODO: This is problematic with multi-byte encodings. This should honestly be a byte-based API
                    // but that would be unperformant in the VM until there's a native byte-array type. The only
                    // use case for this at the moment will only be sending base64 so it's okay (for now).
                    string msg = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead);
                    TranslationHelper.GetEventLoop(vm).ExecuteFunctionPointerNativeArgs(onRecvCb, new object[] { msg });
                } while (bytesRead > 0);
            };
            bgworker.RunWorkerAsync();
            return(null);
        }
Пример #3
0
 private void OnAccept(object state)
 {
     while (!mIsDisposed)
     {
         try
         {
             System.Net.Sockets.Socket asocket = mSocket.Accept();
             AddClient(asocket);
         }
         catch (System.Net.Sockets.SocketException se)
         {
             OnChannelError(this, new ErrorEventArgs {
                 Error = se, Tag = "Server Accept"
             });
             Dispose();
             break;
         }
         catch (Exception e)
         {
             OnChannelError(this, new ErrorEventArgs {
                 Error = e, Tag = "Server Accept"
             });
         }
     }
 }
 public static System.Collections.Generic.IEnumerable <System.Net.Sockets.Socket> IncommingConnections(this System.Net.Sockets.Socket server)
 {
     while (true)
     {
         yield return(server.Accept());
     }
 }
Пример #5
0
                public TestFramework()
                {
                    //  Create a receiving socket.
                    _receiving = new System.Net.Sockets.Socket(_rtspServer.AddressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

                    //  Connect to the server.
                    System.IAsyncResult connectResult = null;
                    connectResult = _receiving.BeginConnect(_rtspServer, new System.AsyncCallback((iar) =>
                    {
                        try { _receiving.EndConnect(iar); }
                        catch { }
                    }), null);

                    //  Get the sender socket to be used by the "server".
                    _sender = _listenSocket.Accept();

                    //  RtspClient default size
                    byte[] buffer = new byte[8192];

                    _client = new Media.Rtp.RtpClient(new Media.Common.MemorySegment(buffer, Media.Rtsp.RtspMessage.MaximumLength, buffer.Length - Media.Rtsp.RtspMessage.MaximumLength));
                    _client.OutOfBandData      += ProcessInterleaveData;
                    _client.RtpPacketReceieved += ProcessRtpPacket;

                    Media.Sdp.MediaDescription md = new Media.Sdp.MediaDescription(Media.Sdp.MediaType.video, 999, "H.264", 0);

                    Media.Rtp.RtpClient.TransportContext tc = new Media.Rtp.RtpClient.TransportContext(0, 1,
                                                                                                       Media.RFC3550.Random32(9876), md, false, _senderSSRC);
                    //  Create a Duplexed reciever using the RtspClient socket.
                    tc.Initialize(_receiving);

                    _client.TryAddContext(tc);
                }
 private void connectionlistener()
 {
     while (true)
     {
         serversock.Listen(5);
         clients.Add(new SocketHandler.clienthandler(serversock.Accept()));
         clientthreads.Add(new System.Threading.Thread(new System.Threading.ThreadStart(clients.Last <SocketHandler.clienthandler>().Start)));
         clientthreads[clientthreads.Count - 1].Start();
     }
 }
Пример #7
0
        static void ListenThreadProc()
        {

            bool keepgoing = true;
            while (keepgoing)
            {
                try
                {
                    if (lsock != null)
                    {
                        lsock.Close();
                    }

                    lsock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
                        System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
                    System.Net.IPEndPoint ipep = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 55905);
                    for (int i = 0; ; i++)
                    {
                        try
                        {
                            lsock.Bind(ipep);
                            break;
                        }
                        catch
                        {
                            if (i >= 5)
                            {
                                throw;
                            }
                            System.Threading.Thread.Sleep(1000 * 4);
                            continue;
                        }
                    }

                    lsock.Listen(30);

                    for (; ; )
                    {
                        System.Net.Sockets.Socket dllclientSock = lsock.Accept();
                        DfsProtocolClientHandler ch = new DfsProtocolClientHandler();
                        System.Threading.Thread cthd = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ch.ClientThreadProc));
                        cthd.IsBackground = true;
                        cthd.Start(dllclientSock);
                    }
                }
                catch (System.Threading.ThreadAbortException e)
                {
                    keepgoing = false;
                }
                catch (Exception e)
                {
                    XLog.errorlog("DfsProtocol.ListenThreadProc exception: " + e.ToString());
                }
            }
        }
 public TcpServerSocket(System.Net.Sockets.Socket ServerSocket) :
     base(
         BeginService: (address) => { ServerSocket.Bind(address); ServerSocket.Listen(int.MaxValue); },
         Disconnect: () => ServerSocket.Disconnect(true),
         WaitForAccept: () => new TcpClientSocket(ServerSocket.Accept())
 {
     IsConnected = true
 })
 {
     this.ServerSocket = ServerSocket;
 }
        static void Main(string[] args)
        {
            //socket used to accept connections
            System.Net.Sockets.Socket g = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.IP);
            g.Bind(new IPEndPoint(IPAddress.Any, 6000));
            Console.WriteLine("Server started at {0}", g.LocalEndPoint);
            List <something> clients = new List <something>();
            List <System.Threading.Thread> clienthreads = new List <System.Threading.Thread>();

            //
            stuffs messagehandling = delegate()
            {
                Queue <string> pendingmessage = new Queue <string>();
                while (true)
                {
                    for (int i = 0; i < clients.Count; i++)
                    {
                        lock (clients[i])
                        {
                            if (clients[i].i.message.Count >= 0)
                            {
                                while (clients[i].i.message.Count > 0)
                                {
                                    pendingmessage.Enqueue(clients[i].i.message.Dequeue());
                                }
                            }//put strings from it into the class
                        }
                    }
                    for (int i = 0; i < clients.Count; i++)
                    {
                        foreach (string v in pendingmessage)
                        {
                            //Console.WriteLine("Adding {0} to Client at {1}", v, clients[i].getipaddress().Address);
                            clients[i].messagestosend.Enqueue(v);
                        }
                    }
                    pendingmessage.Clear();
                }
            };

            System.Threading.Thread handler = new System.Threading.Thread(new System.Threading.ThreadStart(messagehandling));
            while (true)
            {
                g.Listen(5);//the worst way to do threading
                clients.Add(new something(g.Accept()));
                clienthreads.Add(new System.Threading.Thread(new System.Threading.ThreadStart(clients.Last <something>().Startit)));
                clienthreads.Last <System.Threading.Thread>().Start();
                if (handler.ThreadState != System.Threading.ThreadState.Running)
                {
                    handler.Start();
                }
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            var endport = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 26000);
            var port    = new System.Net.Sockets.Socket(endport.AddressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

            port.Bind(endport);
            port.Listen(2);
            while (true)
            {
                var clientconn = port.Accept();
                new ClientStatusVariable(new sunny.Sockets.Socket(clientconn));
            }
        }
Пример #11
0
        internal override async Task <string> CreateAndShowWindowImpl(
            string title,
            byte[] nullableIcon,
            int width,
            int height,
            Func <string, string, bool> handleVmBoundMessage)
        {
            System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(
                System.Net.Sockets.AddressFamily.Unix,
                System.Net.Sockets.SocketType.Stream,
                System.Net.Sockets.ProtocolType.Unspecified);
            socket.Bind(new System.Net.Sockets.UnixDomainSocketEndPoint(this.filePath + "_us"));
            socket.Listen(1);
            System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            bgworker.DoWork += async(e, sender) =>
            {
                System.Net.Sockets.Socket s = socket.Accept();
                SocketReader sr             = new SocketReader(s);
                while (true)
                {
                    int    length  = sr.ReadLength();
                    string data    = sr.ReadString(length);
                    int    colon   = data.IndexOf(':');
                    string type    = colon == -1 ? data : data.Substring(0, colon);
                    string payload = colon == -1 ? "" : data.Substring(colon + 1);

                    if (type == "READY")
                    {
                        StartSocketClient();
                        await this.SendString("SRC", JsResourceUtil.GetU3Source());
                    }
                    else if (type == "VMJSON")
                    {
                        IDictionary <string, object> jsonPayload = new Wax.Util.JsonParser(payload.Substring(1, payload.Length - 2)).ParseAsDictionary();
                        handleVmBoundMessage((string)jsonPayload["type"], (string)jsonPayload["message"]);
                    }
                    else
                    {
                        throw new Exception("Unknown message type: " + type);
                    }
                }
            };

            bgworker.RunWorkerAsync();

            await Task.Delay(TimeSpan.FromMilliseconds(10));

            return(await RunProcess(title, width, height)); // Process ends when window is closed.
        }
Пример #12
0
        static void ListenThreadProc()
        {
            try
            {
                lsock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
                    System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
                System.Net.IPEndPoint ipep = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 55907);
                for (int i = 0; ; i++)
                {
                    try
                    {
                        lsock.Bind(ipep);
                        break;
                    }
                    catch (Exception e)
                    {
                        if (i >= 5)
                        {
                            throw;
                        }
                        System.Threading.Thread.Sleep(1000 * 4);
                        continue;
                    }
                }

                lsock.Listen(30);

                XLog.statuslog("Accepting connections on port " + ipep.Port);

                for (; ; )
                {
                    System.Net.Sockets.Socket dllclientSock = lsock.Accept();

                    System.Threading.Thread cthd = new System.Threading.Thread(
                        new System.Threading.ParameterizedThreadStart(ClientThreadProc));
                    cthd.Name = "ClientThread" + (++userhit).ToString();
                    cthd.IsBackground = true;
                    cthd.Start(dllclientSock);
                }
            }
            catch (System.Threading.ThreadAbortException e)
            {
            }
            catch (Exception e)
            {
                XLog.errorlog("ListenThreadProc exception: " + e.ToString());
            }
        }
        public void Connect()
        {
            System.Net.Sockets.Socket soket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

            soket.Bind(new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 1234));

            soket.Listen(0);

            while (true)
            {
                new System.Threading.Thread(delegate(object obj)
                {
                    System.Net.Sockets.Socket gelenSoket = (System.Net.Sockets.Socket)obj;
                }).Start(soket.Accept());
            }
        }
        public void StartListening()
        {
            System.Threading.Thread ListeningThread = new System.Threading.Thread(() =>
            {
                System.Net.IPAddress ip             = System.Net.IPAddress.Parse(mIp);
                System.Net.IPEndPoint localEndPoint = new System.Net.IPEndPoint(ip, mPort);

                System.Net.Sockets.Socket lister = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

                try
                {
                    lister.Bind(localEndPoint);
                    lister.Listen(10);

                    while (mIsCotinuousConnection)
                    {
                        Console.WriteLine("Waiting for a connection......");
                        mSocket = lister.Accept();
                        Console.WriteLine("Connection sucess");

                        //byte[] data = new byte[2448 * 2048 + 100];
                        byte[] data   = new byte[50];
                        string recStr = null;
                        while (mSocket.Connected)
                        {
                            int len = mSocket.Receive(data);
                            recStr += Encoding.ASCII.GetString(data, 0, len);

                            Console.WriteLine(recStr);

                            recStr = null;
                        }

                        if (mSocket.Connected == false)
                        {
                            Console.WriteLine($"Server {IpAndPort} lose connection.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Occure problem: " + ex.Message);
                }
            });
            ListeningThread.Start();
        }
Пример #15
0
        static StackObject *Accept_3(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Net.Sockets.Socket instance_of_this_method = (System.Net.Sockets.Socket) typeof(System.Net.Sockets.Socket).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Accept();

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Пример #16
0
 public override capex.net.TCPSocket accept()
 {
     if (socket == null)
     {
         return(null);
     }
     System.Net.Sockets.Socket nsocket = null;
     try {
         nsocket = socket.Accept();
     }
     catch (System.Exception e) {
         nsocket = null;
     }
     if (nsocket != null)
     {
         nsocket.NoDelay = true;
         var v = new capex.net.TCPSocketImpl();
         v.socket = nsocket;
         return((capex.net.TCPSocket)v);
     }
     return(null);
 }
Пример #17
0
        static void ListenThreadProc()
        {
            try
            {
                lsock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
                    System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
                System.Net.IPEndPoint ipep = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 55906);
                for (int i = 0; ; i++)
                {
                    try
                    {
                        lsock.Bind(ipep);
                        break;
                    }
                    catch (Exception e)
                    {
                        if (i >= 5)
                        {
                            throw;
                        }
                        System.Threading.Thread.Sleep(1000 * 4);
                        continue;
                    }
                }

                lsock.Listen(30);

                for (; ; )
                {
                    System.Net.Sockets.Socket dllclientSock = lsock.Accept();

                    System.Threading.Thread cthd = new System.Threading.Thread(
                        new System.Threading.ParameterizedThreadStart(ClientThreadProc));
                    cthd.Name = "ClientThread" + (++userhit).ToString();
                    cthd.IsBackground = true;
                    cthd.Start(dllclientSock);
                }
            }
            catch (System.Threading.ThreadAbortException e)
            {
            }
            catch (Exception e)
            {
                XLog.errorlog("ListenThreadProc exception: " + e.ToString());
            }
        }
Пример #18
0
        internal static string UnixSocketServerCreate(VmContext vm, object[] serverOut, string path, Value onRecvCb)
        {
            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(
                System.Net.Sockets.AddressFamily.Unix,
                System.Net.Sockets.SocketType.Stream,
                System.Net.Sockets.ProtocolType.Unspecified);
            serverOut[0] = socket;
            socket.Bind(new System.Net.Sockets.UnixDomainSocketEndPoint(path));
            socket.Listen(1); // TODO: customizable value
            System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            bool intPhase     = true;
            int  targetLength = 0;

            bgworker.DoWork += (e, sender) =>
            {
                System.Net.Sockets.Socket s = socket.Accept();
                byte[] buffer       = new byte[2048];
                int    bytesRead    = 0;
                bool   stillRunning = true;
                while (stillRunning)
                {
                    if (intPhase)
                    {
                        bytesRead = s.Receive(buffer, 0, 1, System.Net.Sockets.SocketFlags.None);
                        if (bytesRead == 0)
                        {
                            stillRunning = false;
                        }
                        else if (buffer[0] == (byte)'@')
                        {
                            targetLength = int.Parse(sb.ToString());
                            intPhase     = false;
                            sb.Clear();
                        }
                        else
                        {
                            sb.Append((char)buffer[0]);
                        }
                    }
                    else
                    {
                        bytesRead = s.Receive(buffer, 0, System.Math.Min(buffer.Length, targetLength), System.Net.Sockets.SocketFlags.None);
                        for (int i = 0; i < bytesRead; ++i)
                        {
                            // TODO: This is problematic with multi-byte encodings.
                            sb.Append((char)buffer[i]);
                        }
                        if (sb.Length == targetLength)
                        {
                            intPhase = true;
                            string msg = sb.ToString();
                            sb.Clear();
                            TranslationHelper.GetEventLoop(vm).ExecuteFunctionPointerNativeArgs(onRecvCb, new object[] { msg });
                        }
                    }
                }
            };
            bgworker.RunWorkerAsync();
            return(null);
        }
Пример #19
0
        static void RunProxy(string sargs)
        {
            System.Net.Sockets.Socket lsock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
                System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
            System.Net.IPEndPoint ep = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 55901);

            try
            {
                for (int i = 0; ; i++)
                {
                    try
                    {
                        lsock.Bind(ep);
                        break;
                    }
                    catch
                    {
                        if (i >= 5)
                        {
                            throw;
                        }
                        System.Threading.Thread.Sleep(1000 * 4);
                        continue;
                    }
                }
                lsock.Listen(2);
                {
                    System.Net.Sockets.Socket ssock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
                        System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
                    System.Net.Sockets.NetworkStream snetstm = null;
                    try
                    {
                        ssock.Connect(System.Net.Dns.GetHostName(), 55900);
                        snetstm = new System.Net.Sockets.NetworkStream(ssock);
                        snetstm.WriteByte((byte)'U');  //start DProcess
                        if (snetstm.ReadByte() != (byte)'+')
                        {
                            throw new Exception("Did not receive a success signal from service.");
                        }
                    }
                    finally
                    {
                        if (snetstm != null)
                        {
                            snetstm.Close();
                            snetstm = null;
                        }
                        ssock.Close();
                        ssock = null;
                    }
                }

                {
                    System.Net.Sockets.Socket csock = lsock.Accept();
                    System.Net.Sockets.NetworkStream cnetstm = null;
                    try
                    {
                        cnetstm = new System.Net.Sockets.NetworkStream(csock);
                        lsock.Close();
                        lsock = null;
                        XContent.SendXContent(cnetstm, sargs);
                        if (cnetstm.ReadByte() != (byte)'+')
                        {
                            throw new Exception("Did not receive a success signal from DProcess.");
                        }
                        StreamStdIO(cnetstm);
                    }
                    finally
                    {
                        if (cnetstm != null)
                        {
                            cnetstm.Close();
                            cnetstm = null;
                        }
                        csock.Close();
                        csock = null;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("RunProxy error: {0}", e.ToString());
            }
            finally
            {
                if (lsock != null)
                {
                    lsock.Close();
                    lsock = null;
                }
            }
        }
Пример #20
0
 protected override ClientSocket <int> OnWaitForAccep()
 {
     return(new WebSocket(new Behavior(S.Accept())));
 }