Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > C# 2012/5.0 General Discussion
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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.
 
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");
            }
        }




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 03:45 AM
DLLs on server pulling server time or client? mussitsch Classic ASP Professional 1 March 1st, 2005 05:38 AM
Receive file via SOAP async dcrooks .NET Web Services 0 January 5th, 2005 05:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.