.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 30th, 2014, 09:22 PM
123456789igor 123456789igor is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2014
Posts: 2 123456789igor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 47 sec
Reputation Power: 0
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  
Old May 1st, 2014, 08:56 AM
123456789igor 123456789igor is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2014
Posts: 2 123456789igor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 47 sec
Reputation Power: 0
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

Viewing: Dev Articles Community ForumsProgramming.NET Development > Sockets client+server with await/async c# 5.0


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap