Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rania1 · Oct 30, 2017 at 02:01 PM · not showing

when u run the scene the console is not showing anything it's multiplayer chat server even when i click the button still nothing showing and there is no error at all

my Server class////// using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Net; using System.Net.Sockets; using UnityEngine;

public class Server : MonoBehaviour { private List Clients; private List DisconnectedList; public int port = 6321; private TcpListener server; private bool ServerStarted; private void start() { Clients = new List(); DisconnectedList = new List(); try { server = new TcpListener(IPAddress.Any, port); server.Start();

         StartListinning();
         ServerStarted = true;
         Debug.Log("server has been start at port" +  port.ToString());
     }
     catch (Exception e){
         Debug.Log("Socket Erreur" + e.Message);
     }
 }
 private void Update()
 {
     if (!ServerStarted)
     {
         return;

     }

     foreach (ServerClient c in Clients)
     {
         if (!IsConnected(c.tcp))
         {
             c.tcp.Close();
             DisconnectedList.Add(c);
             continue;


         }
         else
         {
             NetworkStream s = c.tcp.GetStream();
             if(s.DataAvailable)
             {
                 StreamReader reader = new StreamReader(s, true);
                 string Data = reader.ReadLine();
                 if (Data != null)
                     OnIncomingData(c, Data);

             }
         }
     }
 }
 private bool IsConnected(TcpClient c)
 {
     try
     {
         if(c!=null &&c.Client!=null && c.Client.Connected)
         {
             if(c.Client.Poll(0,SelectMode.SelectRead))
                 {
                 return !(c.Client.Receive(new byte[1], SocketFlags.Peek) == 0);
             }
             return true;
         }
         else
         {
             return false;
         }
     }
     catch
     {
         return false;
     }
 }
 private void StartListinning()
 {
     server.BeginAcceptTcpClient(AcceptTcpClient, server);

         }
 private void AcceptTcpClient(IAsyncResult ar)
 {

     TcpListener Listenner = (TcpListener)ar.AsyncState;
     Clients.Add(new ServerClient(Listenner.EndAcceptTcpClient(ar)));
     StartListinning();
     BroadCast(Clients[Clients.Count - 1].ClientName + "Has Connect", Clients);

 }

private void OnIncomingData(ServerClient c ,string Data) {

     Debug.Log(c.ClientName + "has sent the fellowing messages" + Data);
 }
 private void BroadCast( string data,List<ServerClient> cl)
 {
     foreach( ServerClient c in cl)
     {
         try

         {
             StreamWriter  writer = new StreamWriter(c.tcp.GetStream());
             writer.WriteLine(data);
             writer.Flush();
         }
         catch(Exception e)
         {
             Debug.Log("Writer Erreur :" + e.Message + "To Client :" + c.ClientName); 
         }
     }
 }
 


 public class ServerClient
 {
     public TcpClient tcp;
     public string ClientName;
     public ServerClient( TcpClient ClientSocket)
     {
         ClientName = "Gest";
         tcp = ClientSocket;
     }
 }

} my client class/////// using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Net.Sockets; using UnityEngine; using UnityEngine.UI;

public class Client : MonoBehaviour {

 public GameObject Messageprefabs;
 public GameObject chatcontainairs;
 private bool SocketReady;
 private TcpClient Socket;
 private NetworkStream Stream;
 private StreamWriter writer;
 private StreamReader reader;
 public void ConnectedToServer()
 {
     if(SocketReady)
     {
         return;
         string host = "127.0.0.1";
         int port = 6321;
         string h;
         int p;
         h = GameObject.Find("HostInput").GetComponent<InputField>().text;
         if (h != "")
             host = h;
         int.TryParse(GameObject.Find("PortInput").GetComponent<InputField>().text, out p);
         if (p != 0)
             port = p;
         try
         {
             Socket = new TcpClient(host, port);
             Stream = Socket.GetStream();
             writer = new StreamWriter(Stream);
             reader = new StreamReader(Stream);
             SocketReady = true;

         }
         catch( Exception e)
         {
             Debug.Log("Socket Erreur :" + e.Message);

         }
     }
 }

 private void Update()
 {
     if(SocketReady)
     {
         if(Stream.DataAvailable)
         {
             string data = reader.ReadLine();
             if (data != null)
                 OnIncomingData(data);
         }
     }
 }

 private void OnIncomingData(string data)
 {
     Instantiate(Messageprefabs, chatcontainairs.transform);
 }

 

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

71 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Game Object visible in unity but not visible in mobile apk 0 Answers

Animation occurs but doesn't show in-game 0 Answers

Objects not showing up and have no collider 1 Answer

Storing files on Android not showing up on Windows 1 Answer

How to see geometry 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges