Click here to Skip to main content
15,890,282 members
Home / Discussions / C#
   

C#

 
AnswerRe: Threads in Windows Service Pin
Dave Kreskowiak8-Jul-10 3:35
mveDave Kreskowiak8-Jul-10 3:35 
QuestionCCITT4 compression Pin
Ice_Freez057-Jul-10 15:24
Ice_Freez057-Jul-10 15:24 
AnswerRe: CCITT4 compression Pin
Roger Wright7-Jul-10 15:34
professionalRoger Wright7-Jul-10 15:34 
GeneralRe: CCITT4 compression Pin
Ice_Freez057-Jul-10 15:40
Ice_Freez057-Jul-10 15:40 
GeneralRe: CCITT4 compression Pin
Roger Wright7-Jul-10 16:16
professionalRoger Wright7-Jul-10 16:16 
GeneralRe: CCITT4 compression Pin
Ice_Freez057-Jul-10 16:43
Ice_Freez057-Jul-10 16:43 
AnswerRe: CCITT4 compression Pin
Ennis Ray Lynch, Jr.8-Jul-10 4:22
Ennis Ray Lynch, Jr.8-Jul-10 4:22 
QuestionNeed Help in multithread C# socket programming!!! Pin
yum 20107-Jul-10 9:18
yum 20107-Jul-10 9:18 
Hi everyone!
when i run the programs of server and client, they both run and also show the acknowledgement like
>>Server Started!
>>Client No:1 started!
>>From client-1Message from Client
>>Server to client<1>1
and so on for client 2, 3 ...

but i want communication like if i type some text and then it display that text!!!
I am using visual 2010...

multithread Server program is

using System;
using System.Threading;
using System.Net.Sockets;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TcpListener serverSocket = new TcpListener(8888);
TcpClient clientSocket = default(TcpClient);
int counter = 0;

serverSocket.Start();
Console.WriteLine(" >> " + "Server Started"); 

counter = 0;
while (true)
{
counter += 1;
clientSocket = serverSocket.AcceptTcpClient();
Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
handleClinet client = new handleClinet();
client.startClient(clientSocket, Convert.ToString(counter));
}

clientSocket.Close();
serverSocket.Stop();
Console.WriteLine(" >> " + "exit");
Console.ReadLine();
}
}

//Class to handle each client request separatly
public class handleClinet
{
TcpClient clientSocket;
string clNo;
public void startClient(TcpClient inClientSocket, string clineNo)
{
this.clientSocket = inClientSocket;
this.clNo = clineNo;
Thread ctThread = new Thread(doChat);
ctThread.Start();
}
private void doChat()
{
int requestCount = 0;
byte[] bytesFrom = new byte[10025];
string dataFromClient = null;
Byte[] sendBytes = null;
string serverResponse = null;
string rCount = null;
requestCount = 0;

while ((true))
{
try
{
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
Console.WriteLine(" >> " + "From client-" + clNo + dataFromClient);

rCount = Convert.ToString(requestCount);
serverResponse = "Server to clinet(" + clNo + ") " + rCount;
sendBytes = Encoding.ASCII.GetBytes(serverResponse);
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Flush();
Console.WriteLine(" >> " + serverResponse);
}
catch (Exception ex)
{
Console.WriteLine(" >> " + ex.ToString());
}
}
}
} 
}


the Client program is

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;
namespace client
{
public partial class Form1 : Form
{
System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
msg("Client Started");
clientSocket.Connect("127.0.0.1", 8888);
label1.Text = "Client Socket Program - Server Connected ...";




NetworkStream serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes("Message from Client$");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();

byte[] inStream = new byte[10025];
serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
msg("Data from Server : " + returndata);

}
public void msg(string mesg)
{
textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + mesg;
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

}
}


Plzzzzz guide me.........

Regards
AnswerRe: Need Help in multithread C# socket programming!!! Pin
Eddy Vluggen8-Jul-10 3:12
professionalEddy Vluggen8-Jul-10 3:12 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
yum 20109-Jul-10 2:29
yum 20109-Jul-10 2:29 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
Eddy Vluggen9-Jul-10 3:30
professionalEddy Vluggen9-Jul-10 3:30 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
yum 20109-Jul-10 10:44
yum 20109-Jul-10 10:44 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
Eddy Vluggen9-Jul-10 12:01
professionalEddy Vluggen9-Jul-10 12:01 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
yum 201010-Jul-10 5:35
yum 201010-Jul-10 5:35 
QuestionObtain Solution Classes types in Design Time Pin
adiel20087-Jul-10 5:34
adiel20087-Jul-10 5:34 
AnswerRe: Obtain Solution Classes types in Design Time Pin
Abhinav S7-Jul-10 7:04
Abhinav S7-Jul-10 7:04 
QuestionHow to read a binary file byte by byte and compare its utf8 rendition? [modified] Pin
Shaareable7-Jul-10 5:06
Shaareable7-Jul-10 5:06 
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
harold aptroot7-Jul-10 5:11
harold aptroot7-Jul-10 5:11 
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
OriginalGriff7-Jul-10 5:19
mveOriginalGriff7-Jul-10 5:19 
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
OriginalGriff7-Jul-10 5:28
mveOriginalGriff7-Jul-10 5:28 
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
Richard MacCutchan7-Jul-10 7:03
mveRichard MacCutchan7-Jul-10 7:03 
GeneralRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
Shaareable7-Jul-10 7:15
Shaareable7-Jul-10 7:15 
QuestionHow does one programatically arrange Outlook Tasks by category? Pin
euroazn7-Jul-10 4:24
euroazn7-Jul-10 4:24 
QuestionSeagull Bartender Application Pin
Hum Dum7-Jul-10 0:15
Hum Dum7-Jul-10 0:15 
AnswerRe: Seagull Bartender Application Pin
Pete O'Hanlon7-Jul-10 0:23
mvePete O'Hanlon7-Jul-10 0:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.