Creating An Aplication That Take Users In Server And Making Server Lobby , Create User to Bind Server Lobby And Sending Request for Adding Friend or Sending Message Application Using Visual Studio Part 1 - Server Part

in #utopian-io6 years ago

Repository https://github.com/github/VisualStudio
my project repository https://github.com/aftersteem/server-loby

What will i learn?

  • The concept of how computer make connection with each other.
  • The tcp concept on software.
  • how we can comminicate with any computer and send string concept or make order any computer what ever you want.
  • how can you send string or anything to another computer
  • broadcasting
  • buffer method
  • string to bits concept for making computer understand your command

Requirements

visual studio https://visualstudio.microsoft.com/tr/downloads/?rr=https%3A%2F%2Fwww.google.com.tr%2F

Difficulty

  • intermediate

Tutorial Content

We are going to learn how comminucation is feasible with server and user interface . This is usable for chatting , broadcasting , playing game , the loby of game that user can comminicate with each other , or give order to the computer to decide with each user to give order to server computer which is listening connections.There will be lots of users who connect our server and commincate or request to game for playing something etc.

Outline

  • Connection with each computer
  • Make chatting and requesting like friend or game
  • Understanding of tcp and internet concept
  • Broadcast information with server computer

How to open :

file -> new project -> windows forms applications
for adding button need to open Tool Box
for changing text of button or textfield or richtextbox need to open proporties (with right click) or changing any concept of object whatever you want.

Design Part:

Adding button,

4.png
Adding textbox and label,

5.png

And final part of design for this part ,additionally rich text box

6.png

İmportation

Firstly,we need too make importation of library for using the function of it

using System.Text;   
using System.Threading.Tasks; 
using System.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;

Constraction Our Variable

Firstly, we need to think what we will do on connection

  1. Need to listen incomming connections
  2. Need to check if there is a problem or not
  3. Need to choose which port will be lintening
  4. Need to constract socket
  5. Need to save socket list for identifying who bind us

for all of this we need to make variable:

-for check listening in construction it need to be false on startupping program,for checking if connection is terminate or not (there can be any problem or user who connect our server,quit),socket for binding in our local network whose protocol tcp, in local network protocol is tcp,the list of our socket means that our users .

static bool listening = false; 
static bool terminating = false;
static bool accept = true;
static Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 
 static List<Socket> socketList = new List<Socket>();

START TO LİSTENİNG İNCOMİNG CONNECTİONS

This is the button whose text is listen.We need to broadcast and accept connection in the port which server decide , it can be anything in general use 8080 but it depends on what ever server want or your decissions.I made thread for asynchronous action for avoiding crash on multiple part working.For example if we need to make two loop in same time we need to use thread if not program will crash.We take port number on textbox which take string and we need to parse it integger.In this case we need to use try catch method for avoiding carshes , it can be any problem for example connection fail , any exception.ipaddress.any means that any of ip adress which want to connect our server and serverport , in this method means make our broadcast for this port(YOUR DECİSSION) which we decided. RichTextBox1.AppendText is for making inform to user interface , richtextbox is an object wich we can write something but not user can do , text box is an object which user can write something in it.Listen equal true is aiming if there will be no problem until this line listening equal true because of understanding our server is listening or not.

   private void Listen_Click(object sender, EventArgs e)
        {
            int serverPort;
            Thread thrAccept;

            //this port will be used by clients to connect
            serverPort=Int32.Parse(textBox2.Text);

            try
            {
                server.Bind(new IPEndPoint(IPAddress.Any, serverPort));
                richTextBox1.AppendText("Started listening for incoming connections.");

                server.Listen(3); //the parameter here is maximum length of the pending connections queue
                thrAccept = new Thread(new ThreadStart(Accept));
                thrAccept.Start();
                listening = true;
                infiniteServerInput(); //broadcasting function


            }
            catch
            {
                richTextBox1.AppendText("Cannot create a server with the specified port number\n Check the port number and try again.");
                richTextBox1.AppendText("terminating...");
            }
        }

ACCEPTİNG CONNECTİON

This function for accepting our incoming connection to connect our server.If acceptation is true make our loop.With socketlist.add we add the socket (user) which want to connect our server for identifying users.In the catch part, if there was a problem accept equal to false and trying it to add when there will be no problem for connection.

 private void Accept()
       {
           while (accept)
           {
               try
               {
                   socketList.Add(server.Accept());
                   richTextBox1.AppendText("New client connected...\n");
                   Thread thrReceive;
// thrReceive = new Thread(new ThreadStart(Receive));
                  // thrReceive.Start();
               }
               catch
               {
                   if (terminating)
                       accept = false;
                   else
                       richTextBox1.AppendText("Listening socket has stopped working...\n");
               }
           }
       }
Sort:  

Congratulations @aftersteem! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Your account has been banned from receiving Utopian Reviews due to reported findings of plagiarism and multiple account abuse.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Congratulations @aftersteem! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard!


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Thank you for your contribution.
Please work on improving your future tutorials as follows:

  • Work on your English language, some portions of the tutorial are incomprehensible.
  • Your title is way too lengthy and too narrative, try to make it shorter and straight to the point.
  • Your tutorial concept is too basic.
  • You have picked an incorrect repo. You need to use the proper github repo https://github.com/dotnet/core or for C# in particular https://github.com/dotnet/csharplang (both should work)

Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hi @mcfarhat,

This is a plagiarized tutorial and I reported this to steemcleaners yesterday.
Here is the original post. Was posted 3 days ago. And was deleted by the user after @portugalcoin had reviewed the tutorial.
Additionally, here is the data from the steemblockexplorer.

Great catch @josephace135, thank you! I knew I saw this content before I wasn't hallucinating lol
Actually my theory is a bit different, content being plagiarized or not, both account owners are the same user, and both will be banned.
First user deleted all post content, deleted github repo, and then this user created the post and the new repo.
Either way, both deserve the ban and will be banned accordingly.

Thank you so much @mcfarhat. I was checking my logs for steemcleaners reports and upon checking this post I thought it was steemcleaners comment. LOL
I would agree also to your theory that the same user for both accounts since the posting is very suspicious, hours after it was deleted then this tutorial surfaces.

Hey @josephace135
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

Contributing on Utopian
Learn how to contribute on our website.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @aftersteem! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @aftersteem! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @aftersteem! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!