Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:48:55+00:00 2026-06-05T23:48:55+00:00

Situation: 1. Linux TCP server 2 Windows C# client application The server receives messages

  • 0

Situation:
1. Linux TCP server
2 Windows C# client application

The server receives messages from client, but when I try to send messages from server to the client nothing happens. When I disconnect I get the error:

“Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall.” and it points to the line —> string Response = swRead.ReadLine();

Here is the Client code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;

namespace AsynClient
{
    public partial class Form1 : Form
    {

        private TcpClient client;
        private StreamWriter swSend;
        private StreamReader swRead;

        private bool connected = false;
        string bojaTekst = "", bojaPoz = "";


        private delegate void UpdateLogCallback(string strMessage);

        private Thread thrMessag;

        public Form1()
        {
            Application.ApplicationExit += new EventHandler(OnApplicationExit);
            InitializeComponent();
      }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (connected == false)
            {
                InitializeConnection();
            }
            else
                MessageBox.Show("Vec je uspostavljenja konekcija.");
        }


        private void InitializeConnection()
        {
            client = new TcpClient();
            client.Connect("192.168.100.82", 3456);
            swSend = new StreamWriter(client.GetStream()); //prvo mora da se             konektuje, pa onda ova komanda



            thrMessag = new Thread(new ThreadStart(ReceiveMessages));
            thrMessag.Start();

            connected = true;
            btnSend.Enabled = true;
            btnDisconnect.Enabled = true;
            txtMsg.Enabled = true;
            btnConnect.Enabled = false;

        }

        private void UpdateLog(string strMessage)
        {

            txtServ.AppendText(strMessage + "\r\n");

        }

        private void ReceiveMessages()
        {
            swRead = new StreamReader(client.GetStream());

            string Response = swRead.ReadLine();

            while (connected)
            {

                // Show the messages in the log TextBox

                this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] {         swRead.ReadLine() });

            }
        }

        private void btnSend_Click(object sender, EventArgs e)
        {

            if (listBoxTekst.SelectedIndex == -1)
                listBoxTekst.SelectedIndex = 0;

            if (listBoxPozadina.SelectedIndex == -1)
                listBoxPozadina.SelectedIndex = 0;

            bojaTekst = listBoxTekst.Text;
        bojaPoz = listBoxPozadina.Text;


        SendMessage();
    }

    private void SendMessage()
    {
     txtMsg.Text);

        if (txtMsg.Lines.Length >= 1)
        {
            swSend.WriteLine(bojaPoz + "\t" + bojaTekst + "\t" + txtMsg.Text + "\t"); 
            swSend.Flush();                     
            txtMsg.Lines = null;                
        }                                       
        txtMsg.Text = "";
    }

    private void btnDisconnect_Click(object sender, EventArgs e)
    {
        char[] quit = new char[5];
        quit[0] = 'q'; quit[1] = 'w'; quit[2] = 'w'; quit[3] = 'w'; quit[4] = '\0';
        connected = false;

        btnConnect.Enabled = true;
        btnSend.Enabled = false;
        btnDisconnect.Enabled = false;
        txtMsg.Enabled = false;

        swSend.WriteLine(quit);
        swSend.Flush();

        swSend.Close();
        client.Close();
    }

    public void OnApplicationExit(object sender, EventArgs e)
    {
        if (connected == true)
        {
            connected = false;

            swSend.WriteLine("qwww"); //proveri da li radi f-ja kako treba
            swSend.Flush();

            swSend.Close();
            client.Close();
        }
    }      
}

}

The server side receives the messages with the read() function and it works fine, but when it sends with write() the C# client doesn’t receive the message.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:48:57+00:00Added an answer on June 5, 2026 at 11:48 pm

    Just one thing (there mioght be other problems):
    You have a connected variable, which value you set to true, after you start your listening thread. The loop within the thread doesnt even run once.

    thrMessag = new Thread(new ThreadStart(ReceiveMessages));   
    thrMessag.Start();              
    connected = true; //here is your first bug, should come before the previos line
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my situation:     I have a linux server/media center with a
I have a client server situation in which I receive data using read(socket, char_buf,
Here is the situation. There are server and client in network. They communicate like
We have application that involves C++ socket server, Flash client that communicates with C++
I usually work on a Linux system, but I have a situation where I
This is the situation: I have server with linux, and there is two databases
I really have a strange situation. I'm making a Linux multi-threaded C application using
Amazon's EC2 service offers a variety of Linux and Windows OS choices, but I
Hypothetical situation. I have a command line program in *nix (linux, BSD, etc.). It
Situation is you have to develop an application against an Active Directory Tree. Want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.