Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: From C# to Java

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default From C# to Java

    I want to do theese lines in java...
      protected Socket _sck;
            protected string _host;
            protected UInt16 _port;
     
     
            public void Connect(string RemoteHostIP, UInt16 RemotePort)
            {
                if (this._sck != null)
                {
                    this._sck.Close();
                    this._sck = null;
                }
     
                this._sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                this._host = RemoteHostIP;
                this._port = RemotePort;
                try
                {
                    this._sck.BeginConnect(new IPEndPoint(IPAddress.Parse(this._host), this._port), new AsyncCallback(this.onSocketConnected), this._sck);
     
                    // Raise the event.
                    this.OnConnectionAttempt(new SocketConnectEventArgs(this._host, this._port));
                }
                catch (SocketException se)
                {
                    this.OnSocketError(new SocketErrorEventArgs(se.ErrorCode, se.Message));
                }
            }
    -------------------------------------------------------------------------- From There... 
     private void onDataReceived(IAsyncResult ar)
            {
                SocketPacket myData = (SocketPacket)ar.AsyncState;
     
                try
                {
                    int bRx = myData.assocSocket.EndReceive(ar);
     
                    if (bRx > 0)
                    {
                        // Raise the event.
                        this.OnRecieveData(new SocketRecvEventArgs(bRx, myData.dataBuffer));
     
                        // Resume the recv loop.
                        this.WaitForData();
                    }
                    else
                    {
                        // Raise the event.
                        //this.OnDisconnect(new EventArgs());
                    }
                }
                catch (SocketException se)
                {
                    this.OnSocketError(new SocketErrorEventArgs(se.ErrorCode, se.Message));
                }
                catch (ObjectDisposedException oe)
                {
                    // It's dead.  We're just still receiving?
                }
            }
     
            private void onDataSent(IAsyncResult ar)
            {
                Socket sck = (Socket)ar.AsyncState;
     
                try
                {
                    int bTx = sck.EndSend(ar);
     
                    // Raise the event.
                    this.OnSendData(new SocketSendEventArgs(bTx));
                }
                catch (SocketException se)
                {
                    this.OnSocketError(new SocketErrorEventArgs(se.ErrorCode, se.Message));
                }
            }
     
            private void onSocketConnected(IAsyncResult ar)
            {
                Socket sck = (Socket)ar.AsyncState;
     
                try
                {
                    sck.EndConnect(ar);
     
                    // Raise the event.
                    this.OnConnect(new SocketConnectEventArgs(this._host, this._port));
     
                    // Start the receiving loop.
                    this.WaitForData();
                }
                catch (SocketException se)
                {
                    this.OnSocketError(new SocketErrorEventArgs(se.ErrorCode, se.Message));
                }
            }
     
            private void onSocketDisconnected(IAsyncResult ar)
            {
                Socket sck = (Socket)ar.AsyncState;
                try
                {
                    sck.EndDisconnect(ar);
     
                    // Raise the event.
                    this.OnDisconnect(new EventArgs());
                }
                catch (SocketException se)
                {
                    this.OnSocketError(new SocketErrorEventArgs(se.ErrorCode, se.Message));
                }
            }
    thx!!
    Last edited by helloworld922; February 25th, 2010 at 04:11 PM.


  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: From C# to Java

    Bump...
    The problem is this : IAsyncResult ar

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: From C# to Java

    I'm confused. Can you please explain the problem a little more..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: From C# to Java

    Yes, this is a C# DLL that I translate it in Java, but I stuck in this lines...This is to connect to a server but I have a problem with :IAsyncResult