|
I didnt even cant connect to the other computer ..... that is why I cant do other stuffs ... like to check wheterh the my messages reachs there??
How could I do that ?
|
|
|
|
|
The other computer would have to have a client set to receive 'messages' from your end (which is also a client), that client would have the logic to confirm receipt of data in its entirety.
|
|
|
|
|
Hey buddy ... I think u didnt get ma idea ...... Here is z code what I am working on(Msdn's code)
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
public class GetSocket
{
private static Socket ConnectSocket(string server, int port)
{
Socket s = null;
IPHostEntry hostEntry = null;
hostEntry = Dns.GetHostEntry(server);
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, port);
Socket tempSocket =
new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
@ the last line of z above code .... it is the place where the problem occurs @ run time .....
it says "a socket was trying to unreachable network 127.0.0.1:80
and here is the remaining code
if(tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}
private static string SocketSendReceive(string server, int port)
{
string request = "GET / HTTP/1.1\r\nHost: " + server +
"\r\nConnection: Close\r\n\r\n";
Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
Byte[] bytesReceived = new Byte[256];
Socket s = ConnectSocket(server, port);
if (s == null)
return ("Connection failed");
s.Send(bytesSent, bytesSent.Length, 0);
int bytes = 0;
string page = "Default HTML page on " + server + ":\r\n";
do {
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
}
while (bytes > 0);
return page;
}
public static void Main(string[] args)
{
string host;
int port = 80;
if (args.Length == 0)
host = Dns.GetHostName();
else
host = args[0];
string result = SocketSendReceive(host, port);
Console.WriteLine(result);
Console.Read();
}
}
If u got it please help me
|
|
|
|
|
Looks like you are trying to connect to yourself! 127.0.0.1 is loopback address, not the remote computer. btw this is really a TCP/IP issue and not C#.
|
|
|
|
|
That is what I was thinking .............. So how can I search the IPs of another computers in my networkk?............
Richard MacCutchan wrote: btw this is really a TCP/IP issue and not C#.
The connection works perfectly for datasharing,internet sharing, So I hope it is not a TCP/IP question. Or is there something that I didnt know abt?
Thank you.
|
|
|
|
|
Mati,
I have tried your code on my system and the following occurred:
1. run program with NO parameters on command line. The default action in function Main() is to use the hostname of the machine that the code is running on. In this case the IP address resolves to 127.0.0.1 and the connect fails as there is no listener at port 80.
2. Run with the name of my remote system in the command and the connection works; but not completely as I have no port 80 listener on that system either.
As I said before this is really a TCP/IP question and that is about the extent of my knowledge.
|
|
|
|
|
So do you think it will work if I am give the address of the other client computer(i.e not the host where the program is running)
Richard MacCutchan wrote: I have no port 80 listener on that system either.
Can u tell me about how do I know if wheterh port 80 listner in my system exists or not?
Thank you
|
|
|
|
|
You need to give either the IP address or DNS (network) name of the computer that you are trying to connect to, in order to communicate. From what I can see of your code you are trying to send a HTTP request to port 80 (HTTP server port) of the destination machine. This means that you must have a Web server process running on that machine, which will listen on port 80 by default.
From your questions I suspect that you need to spend some more time studying TCP/IP and general network communication before proceeding further.
I repeat this question really belongs in an alternative forum as it is not a C# issue.
|
|
|
|
|
Thank you for ur help body. I should read more........ Even if I learned Networking around 36 credit hour I should read more abt Socket and networking ........ thanks for ur help ........ I will contact u if i have any questions. with this thread ......... by z way do u have an experience working on Socket Programming??
Thank you
|
|
|
|
|
Mati,
My experience of socket programming was on UNIX rather than Windows systems and was sometime ago, so I have probably forgotten quite a lot. I cannot really provide an online tutorial for you so I would repeat my earlier advice to go and study some tutorials and other publications before proceeding further. If you still have problems in the future then reopen your questions in the correct forum, as these are really not C# issues.
regards,
Richard
|
|
|
|
|
If it is difficult, then is there a portable compiler that I can use?
|
|
|
|
|
You compile it from the command line using csc.exe .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The C# Express Edition is free. So is SharpDevelop.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
|
It's not difficult and more developers should learn to do it; it's a very useful tool to have.
When you install .net, the C# and VB.net compilers are installed as well (these are the same compilers that Visual Studio uses).
0. Open a DOS box; there are at least two ways to do this:
Start|Run cmd
Start|Programs|Accesories|Command prompt
Because I use a DOS box extensively I have it on my Quick launch toolbar
1. Determine which versions of the compiler you have:
C:\>dir /s /b "c:\windows\microsoft.net\framework\csc.exe
c:\windows\microsoft.net\framework\v1.1.4322\csc.exe
c:\windows\microsoft.net\framework\v2.0.50727\csc.exe
c:\windows\microsoft.net\framework\v3.5\csc.exe
C:\>
2. Execute the compiler of your choice, specifying your source code as a parameter:
C:\>c:\windows\microsoft.net\framework\v3.5\csc.exe Hello.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
C:\>
3. Execute the program:
C:\>hello
Hello, world!
C:\>
4. If you do this frequently, you may want to write a BAT file to do this:
C:\>type csc.bat
@c:\windows\microsoft.net\framework\v3.5\csc.exe %*
C:\>
5. And/or add the compiler's directory to the Path environment variable
Start|Settings|Control panel|System|Advanced|Environment variables|System variables|Path|Edit
|
|
|
|
|
don't do it with notepad.
use the express version, microsoft intellisense is realy powerfull tool.
it helps you write code while you type it.
if you have coding experience with visual studio, please ignore this message.
but if you haven't, i couldn't imagen to memorize or search for all the properties a component/control or whatever has.
Bad = knowing 2 much
|
|
|
|
|
Use EditPlus?
You will still need the CSC.exe (Visual Studio) installed.
|
|
|
|
|
Doesn't csc.exe comes with the framework and not Visual Studio?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Why make life difficult for yourself? Get a copy of C# 2008 Express from Microsoft; it's a superb product and it is free. And if you still want to use Notepad and command line compile then check out the C# compiler pages on MSDN.
|
|
|
|
|
I need to develop a program that plays the signals which are arrived from an external device as follow. My problem is that there are artifacts in the onset and offset of each stream (sound.Play(data)).
what's the solution?
using System;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
using System.IO;
namespace TestSound
{
class CSound : Form
{
const int HEADER_SIZE = 44;
const bool FLAG_STEREO = true;
const short BITS_PER_SAMPLE = 16;
const int SAMPLE_RATE = 44100;
int numberOfSamples;
MemoryStream stream;
BinaryWriter writer;
Device ApplicationDevice = null;
SecondaryBuffer buffer = null;
BufferDescription description;
public CSound()
{
try
{
ApplicationDevice = new Device();
}
catch
{
MessageBox.Show("Unable to create sound device.");
ApplicationDevice = null;
return;
}
ApplicationDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
description = new BufferDescription();
description.ControlEffects = false;
stream = new MemoryStream();
writer = new BinaryWriter(stream);
}
private void AddHeader()
{
stream.Position = 0;
writer.Write(0x46464952);
writer.Write((int)(HEADER_SIZE + (numberOfSamples * BITS_PER_SAMPLE * (FLAG_STEREO ? 2 : 1) / 8)) - 8);
writer.Write(0x45564157);
writer.Write(0x20746d66);
writer.Write(16);
writer.Write((short)1);
writer.Write((short)(FLAG_STEREO ? 2 : 1));
writer.Write(SAMPLE_RATE);
writer.Write(SAMPLE_RATE * (FLAG_STEREO ? 2 : 1) * BITS_PER_SAMPLE / 8);
writer.Write((short)((FLAG_STEREO ? 2 : 1) * BITS_PER_SAMPLE / 8));
writer.Write(BITS_PER_SAMPLE);
writer.Write(0x61746164);
writer.Write((int)(numberOfSamples * BITS_PER_SAMPLE * (FLAG_STEREO ? 2 : 1) / 8));
}
public void Play(short[] samples)
{
if (ApplicationDevice == null)
return;
stream.Position = HEADER_SIZE;
numberOfSamples = samples.Length;
for (int i = 0; i < numberOfSamples; i++)
{
writer.Write(samples[i]);
if (FLAG_STEREO)
writer.Write(samples[i]);
}
AddHeader();
stream.Position = 0;
try
{
if (buffer != null)
{
buffer.Dispose();
buffer = null;
}
buffer = new SecondaryBuffer(stream, description, ApplicationDevice);
buffer.Play(0, BufferPlayFlags.Default);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
public class Test
{
CSound sound = new CSound();
void Run()
{
short[] data;
port.Read(data);
sound.Play(data);
}
}
}
I think I should find a way to add new stream to current stream instead of destroying the current stream and creating new one(buffer.Dispose(); buffer = null; buffer = new...)
what's your suggestions?
|
|
|
|
|
Hi all,
I try to making a user control that show data from dataset, how I do for pass the dataset to any property and in other property display automaticaly all the fields of this dataset ??
Thanks in advance.
|
|
|
|
|
By implementing a DataSource propery and a DataMember property
Something like this:
private object dataSource = null;
private string dataMember = string.Empty;
[
Category("Data"),
Editor("SystemWindows.Forms.Design.DataMemberListEditor, System.Design", typeof(UITypeEditor))
]
public string DataMember
{
get
{
return this.dataMember;
}
set
{
this.dataMember = value;
}
}
[
Category("Data"),
AttributeProvider(typeof(IListSource)),
TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")
]
public object DataSource
{
get
{
return this.dataSource;
}
set
{
this.dataSource = value;
}
}
It may be more complicated than this, but these are the basics. Look up any of the terms on MSDN for more detail.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to use taglib# in my serial id3 tagger (c) project, but I can't find out how to use/assign the taglib-libraries[^].
So where do I copy which files of the libraries and how do I assign them to my project? (as in: do I put using <k:\d\dev\taglib\taglib.h> ; in the header?)
|
|
|
|
|
pietlut wrote: So where do I copy which files of the libraries
If you want to add project to solution copy files to solution folder, or yust copy dll to your project
pietlut wrote: how do I assign them to my project? (as in: do I put using <k:\d\dev\taglib\taglib.h>; in the header?)
Absolutly not that whay. This is not C++. Yust add to solution as exsisting project, then under main projet add reference to another project. Or you can yust copy dll files to your project, add reference to it and when you will run, those dll will be automatcly copied to same folder as exe file
And then you can use: using NameOfNameSpace;
|
|
|
|
|