|
Hi,
Im writing a very simple network chat app. This is only a chat app for two people over network.
Here is my code:
<br />
public partial class MyChat : Form<br />
{<br />
Socket sock;<br />
Thread receiver;<br />
static IPAddress localIPAddr;<br />
static int intPort;<br />
IPEndPoint multiep;<br />
<br />
public MyChat()<br />
{<br />
InitializeComponent();<br />
<br />
localIPAddr = IPAddress.Parse(txtHost.Text);<br />
intPort = Convert.ToInt32(txtPort.Text.ToString());<br />
<br />
multiep = new IPEndPoint(localIPAddr, 4040);<br />
sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); <br />
<br />
IPEndPoint iep = new IPEndPoint(IPAddress.Any, intPort);<br />
sock.Bind(iep);<br />
<br />
sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(localIPAddr));<br />
<br />
receiver = new Thread(new ThreadStart(packetReceive));<br />
receiver.IsBackground = true;<br />
receiver.Start(); <br />
}<br />
<br />
void packetReceive()<br />
{<br />
EndPoint ep = (EndPoint)multiep;<br />
byte[] data = new byte[1024];<br />
string stringData;<br />
int recv;<br />
while (true)<br />
{<br />
recv = sock.ReceiveFrom(data, ref ep);<br />
stringData = Encoding.ASCII.GetString(data, 0, recv);<br />
rtxtMsgWindow.AppendText("from " + ep.ToString() + ": " + stringData);<br />
}<br />
}<br />
<br />
private void btnExit_Click(object sender, EventArgs e)<br />
{<br />
receiver.Abort();<br />
sock.Close();<br />
Close(); <br />
} <br />
<br />
private void txtMessage_KeyPress(object sender, KeyPressEventArgs e)<br />
{<br />
if (e.Handled = e.KeyChar == 13)<br />
{<br />
byte[] message = Encoding.ASCII.GetBytes(txtMessage.Text);<br />
txtMessage.Clear();<br />
sock.SendTo(message, SocketFlags.None, multiep);<br />
}<br />
}<br />
}<br />
<br />
Problem is i get the following socket exception The requested address is not valid in its context at the line of code i made bold above.
The specified ip address would be my own ip address to test and see if the message gets posted. If this is the problem is there any other way i could get around this maybe a different way of socket programming maybe using tcpclient or something?
Im a noob to sockets or network programming pls help thx
Regards
|
|
|
|
|
Hi.
I'm writing a client for a webservice which is built on Java. Some operations provided by the service send attachments to the client calling them. The standard used by the server for this task is MIME(SOAP with Attachments). As some of you might know, the .NET Framework and WSE don't have(and never will have) any support for SwA/MIME.
Does anyone has knoleddge of the existance of a good free/afordable component for .NET which can handle MIME responses from webservices? I only found one such beast, written by Alotsoft, but it cost $5000...
Thanks Alot.
|
|
|
|
|
|
Which event should be handled before closing form, so closing can be canceled. Now I handle OnClosing and OnClosed but returning from these on Cancel, closes the form anyway.
|
|
|
|
|
use FormClosing or FormClosed event instead. and use e.Cancel=true;
|
|
|
|
|
in the "closing" event of that form put following line
e.cancel = true;
form closing will be cancelled.
Rahul Kulkarni
|
|
|
|
|
|
Application in c# that opens a word file.
The Application included a reference to the Microsoft Word 11.0 Object Library and Microsoft Office 11.0 Object Library.
On computer with word 2003 the application runs ok but on computer with word 2000 got error message:
"Microsoft.Office.Interop.Word
Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Can anyone suggest a solution?
Is there backwards compatibility with the interop assemblies?
Thanks
|
|
|
|
|
AFAIK there is no backwards compatibility.
For Office 2003 its the Microsoft Office 11.0 Object Library
For Office 2002 its the Microsoft Office 10.0 Object Library
and for Office 2000 its Microsoft Office 9.0 Object Library (I think)
|
|
|
|
|
I need to open the word document in all word versions
How can I do that?
|
|
|
|
|
No backwatrd compatibility means you can only open one specific version of Word with a given dll. However, these programs themselves contain backward compatibility, so I recommend to use dll version 11.0 (Word 2003), that way you can open earlier version doc files.
|
|
|
|
|
The application has to support all word versions.
|
|
|
|
|
|
|
Hi all,
we generate xml code with our application and then we create a html document by combining th xml and pre-created xsl. We use the following code to print the resulting html document...
Process myProcess = new Process();<br />
myProcess.StartInfo.FileName = TemplatePath + "\\Invoice.HTML";<br />
myProcess.StartInfo.Verb = "Print";<br />
myProcess.StartInfo.CreateNoWindow = true;<br />
myProcess.Start();
Now, are there any added lines that would remove the header (by default: Page 1 of 1) and the footer (by default: "the file path" and "todays date") before i print the document?
Thank you in advance
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
You cannot do this in code, you will have to do this in IE. File->Page Setup then clear the header and footer boxes. Or if you use any other browser then check their documentation on how to do this.
|
|
|
|
|
o okay. I thought as much... so the client will just have to do this on their own...
thank you for your time.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
No problem. I had a week's worth of struggling with that same thing. what I did in the end was just create a pdf document instead and print that (using Crystal Reports) - for some reason this did not include the header and footer. (I had to create a document that could be printed online)
|
|
|
|
|
Hi all,
I am using Listview control in vb.net 2005, in that i am using a column header in that. I wish to change the style(back color) of the column header. I searched for it in the Properties, but i can't found it. Can any one suggest me how to change the Backcolor of the column header.
It's little urgent plz
Thanks in advance
I am using Outlook express to read all the mails in the inbox.How can i know the connecting url of my outlook express.
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
you'd have to set OwnerDrawand property to true and add DrawColumnHeader, DrawItem or DrawSubItems event..
life is study!!!
|
|
|
|
|
hi seishin,
Really thanks for your help.Could you please suggest me some code samples for implementing the same.I am really new to this concept.
So if you could send me some sample code, it would be of great use.
Thanks in advance.
I am using Outlook express to read all the mails in the inbox.How can i know the connecting url of my outlook express.
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
http://www.codeproject.com/cs/miscctrl/customheader.asp
life is study!!!
|
|
|
|
|
I am developing a c# application which opens a .xls file using Excel object of c#.
If the file is already opened by another user for writing I need to display that users name in a MessageBox.
I have noticed that if Excel objects DisplayAlerts option is set true Excel application displays a messagebox for notifying the username who is modifying the file. But I want to display customised messagebox from my application.
Please help me. Solution required urgently.
|
|
|
|
|
Hi,
I don't know which shade of lipstick to apply tonight - any suggestions
Seriously though, I have the following code populate a multiline text box:
DateTime currentDateTime = DateTime.Now;<br />
string now = currentDateTime.ToString("MMM dd, yyy");<br />
textBoxMemberNotes.Text = now + Environment.NewLine + Environment.NewLine;
The problem I wish to overcome is that the resultant text is highlighted and if the user just starts typing then the text inserted by the above code is rightfully deleted.
How can I "move the cursor" (so to speak) programatically so that this doesn't happen?
Thanks in advance
Glen Harvy
|
|
|
|
|
The following should work (maybe you have to tweak the parameters). Alternatively you can set the SelectionStart and SelectionLength properties.
textBoxMemberNotes.Select(textBoxMemberNotes.Length - 1, 0);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|