First C# Socket

A place to discuss development on the Microsoft .NET framework platform utilizing languages such as C#, Visual Basic, J# and Managed C++

Moderators: IRC Operators, Support Team

User avatar
Swede
User
User
Posts: 245
Joined: Wed Mar 07, 2007 1:59 pm
Location: Sweden

First C# Socket

Postby Swede » Thu Sep 13, 2007 5:44 pm

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace Socket
{
    class Socket
    {
        static void Main(string[] args)
        {
            try
            {
                WebClient RuneScape = new WebClient();
                Stream psocket = RuneScape.OpenRead("http://www.runescape.com/title.ws");
                StreamReader playerread = new StreamReader(psocket);
                string sockread = null;
                while ((sockread = playerread.ReadLine()) != null)
                {
                    if (sockread.StartsWith("There are"))
                    {
                        Console.WriteLine(sockread);
                        break;
                    }
                }
                psocket.Close();
                Console.Read();
            }
            catch
            {
                Console.WriteLine("Socket error :(");
            }

        }
    }
}


and in an exe here:

http://eddie.veritynet.net/~MightScript/Socket1.exe


Credits to Chessnut as some parts are pretty much the same(he told me it was ok :))

Time to make some harder ones :D
Swede/Bjorn on IRC
mIRC Scripter since 10 April 2007
rangerguy39
User
User
Posts: 397
Joined: Wed Jun 06, 2007 4:06 pm

Postby rangerguy39 » Thu Sep 13, 2007 7:27 pm

thats nice
good job
add

Code: Select all

console.readline();
so it doesnt automatically close when opened
User avatar
Swede
User
User
Posts: 245
Joined: Wed Mar 07, 2007 1:59 pm
Location: Sweden

Postby Swede » Fri Sep 14, 2007 5:43 am

rangerguy39 wrote:thats nice
good job
add

Code: Select all

console.readline();
so it doesnt automatically close when opened


it doesnt close :$
Swede/Bjorn on IRC

mIRC Scripter since 10 April 2007
Ward
User
User
Posts: 615
Joined: Sat Jul 21, 2007 10:57 pm
Location: Brussels, Belgium
Contact:

Postby Ward » Fri Sep 14, 2007 12:48 pm

rangerguy39 wrote:thats nice
good job
add

Code: Select all

console.readline();
so it doesnt automatically close when opened


He already has a Console.Read(); ..

Though you might want to add one in the catch part

or just one after the try-catch construction :)
rangerguy39
User
User
Posts: 397
Joined: Wed Jun 06, 2007 4:06 pm

Postby rangerguy39 » Fri Sep 14, 2007 7:13 pm

Ze Smelly Swede wrote:
rangerguy39 wrote:thats nice
good job
add

Code: Select all

console.readline();
so it doesnt automatically close when opened


it doesnt close :$
oh sorry... i overlooked it

Return to “.NET”

Who is online

Users browsing this forum: No registered users and 1 guest