Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Client not reciving a message from the server, not sure whats wrong
    primarykey
    data
    text
    <p>Please tell me whats wrong. also note iv been trying to debug this so some code might be extra and not needed but shouldn't keep it from working. I know its the client not ever receiving the message because I used console.write on both sides of it and only the above the socket.read() showed. I left those two console.write out on this post. </p> <p>server:</p> <pre><code>class class1 { static void Main(string[] args) { TcpListener serverSocket = new TcpListener(IPAddress.Any, info.Port); TcpClient clientSocket = default(TcpClient); serverSocket.Start(); log.write("&gt;&gt; Listening for Clients\n"); bool running = true; while (running) { clientSocket = serverSocket.AcceptTcpClient(); newClient client = new newClient(clientSocket,log); Thread clientThread = new Thread(new ThreadStart(client.start)); clientThread.Start(); } } } class Client { private clientType cType; private EndPoint cIP; private TcpClient socket; private NetworkStream cStream; public NetworkStream stream { get { return cStream; } } public clientType Type { get { return cType; } set { cType = value; } } public EndPoint IP { get { return cIP; } set { cIP = value; } } public Client(TcpClient clientSocket) { socket = clientSocket; cStream = socket.GetStream(); } } class newClient { Client client; public newClient(tcpClient socket) { client = new Client(socket); } public void start() { loginObj loginRequest = new loginObj(); BinaryFormatter formatter = new BinaryFormatter(); MemoryStream memory = new MemoryStream(); formatter.Serialize(memory, loginRequest); byte[] tempOutBytes = new byte[10025]; byte[] outBytes; int numOfBytes = memory.read(tempOutBytes,0,tempOutBytes.Length); outBytes = new byte[numOfBytes]; for(int counter = 0; counter &lt; nuOfBytes; counter++) outBytes[counter] = tempOutBytes[counter]; client.stream.Write(outBytes,0,outBytes.Length); //Rest of code waits for respond but client never gets the message so rest of code is not needed } } </code></pre> <p>client:</p> <pre><code>class network { private TcpClient socket = new TcpClient(); public void start() { NetworkStream stream = socket.GetStream(); MemoryStream memory = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); byte[] tempInBytes = new byte[10025]; byte[] inBytes; int numOfBytes = stream.Read(tempInBytes,0,tempInBytes.Length); inBytes = new byte[numOfBytes]; for(int counter = 0; counter &lt; numOfBytes; counter++) inBytes[counter] = tempInBytes[counter]; memory.write(inBytes,0,inBytes.Length); object msgObj = formatter.Deserialize(memory); Type msgType = msgObj.GetType(); if(msgType == typeof(loginObj)) { console.write("It works"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload