Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > C# 2012/5.0 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2012/5.0 General Discussion Discussions about the C# 2012 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2012/5.0 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 30th, 2014, 09:25 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default sockets client+server with await/async c# 5.0

Hello, i try to write a simple asynchronous client/server apps. I know how do it using callback, but i want to invistigate how write client+server using await/async and c# 5.0. Please, help me. It should be simple. Only connect and transfer some bytes.
I know that this can be done using Tasks.
Something like this:
Code:
public static Task ConnectAsync(this Socket socket, EndPoint remoteEP)
        {
            return Task.Factory.FromAsync(socket.BeginConnect, socket.EndConnect, remoteEP, null);
        }
I try to find some examples, but this has no effect.
FYI. without tcplistener and NetworkStream.
Reply With Quote
  #2 (permalink)  
Old May 1st, 2014, 08:58 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Connect success. But how to send bytes, i don't know
Code:
private readonly Socket _server;
        public ServerSocket(IPAddress ipAddress, int port)
        {
            _server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _server.Bind(new IPEndPoint(ipAddress, port));
            _server.Listen(20);
            Console.WriteLine("Wait connection");
            Accept();
        }
        private async void Accept()
        {
            for (; ; )
            {
                var socket = await Task.Factory.FromAsync<Socket>(_server.BeginAccept, _server.EndAccept, true);
                Console.WriteLine("Connected");
            }
        }
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
identify async file upload progress harshil.sh ASP.NET 2.0 Professional 0 July 22nd, 2011 01:49 AM
Fast and Efficient Async SQL Process rodmcleay ASP.NET 1.x and 2.0 Application Design 0 November 9th, 2007 02:45 AM
DLLs on server pulling server time or client? mussitsch Classic ASP Professional 1 March 1st, 2005 04:38 AM
Receive file via SOAP async dcrooks .NET Web Services 0 January 5th, 2005 04:15 PM



All times are GMT -4. The time now is 04:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.