
coldfusion244
Avatar/Signature-
Posts
269 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by coldfusion244
-
Here is reproducable code. Here
-
Textbox code to make certain things bold and different color
coldfusion244 replied to Lanc1988's topic in Windows Forms
Use a richtextbox, not a regular one. RichTextBox -
This isn't vb.net, it's C#.net but the CS tags make the code look horrid. private void CheckPackets(IAsyncResult result) { try { Socket socket = (Socket) result.AsyncState; int dsocket = socket.EndReceive(result); if (dsocket<=0) { t1.Text += "\r\nNothing found!"; } else { t1.Text +="\r\nGot: " + System.Text.Encoding.UTF8.GetString(rcvd); Action(System.Text.Encoding.UTF8.GetString(rcvd),socket); socket.BeginReceive(rcvd,0,rcvd.Length,System.Net.Sockets.SocketFlags.None, new AsyncCallback(CheckPackets),socket); //rcvd = new byte[65535]; } } catch { } }
-
Sorry HJB, thought I was done but guess not. Basically what is happening: I have a server and multiple clients. Data is sent to the server from an outside source that I choose. Once the server digests the information into actual parts, it sends that to certain clients or in cases, all. I have it set to show me what it sends and recieves. The onyl problem I am having is that I have no clue how to control the recieve buffer. I made a global byte for this but I never know when to clear it. I tried it in several different places but no avail. Either it erases the data or keeps the data. I'll post the code if need be, but there is a good bit of it. I have been looking all over for a *good* example of asynchronous sockets, so if you know of one please link it. Thank you to all. -Sean
-
Thank you sir. -THREAD RESOLVED-
-
Simon, you will probably want to refer to this thread which I made about the same thing. Here -Sean
-
Hi, I am used ot programming in Visual Basic 6.0, in which the IDE automatically created the Form_Load and such functions by means of selecting them from a dropdown combo. I believe I saw a post on it in here but for the life of me I am unable to find it. Does anyone know how to set the IDE to do that? Maybe it's just a VB thing...
-
I am so stupid.... I had the function sending blank messages. I didn't put the beginsend inside the braces! so whether or not information was there it sent itself in a constant never ending loop! wow, I think i've been staying up way too late... :p Thanks for everything again HJB, you're a huge asset to the community! -THREAD RESOLVED-
-
Which part of the code? Should I just have the connection part or all of it? I tried to debug it, although nothing I did seemed to help :confused:
-
There is probably a better way to do this, but I would use another form that is borderless...
-
Ok, everything works now! Thanks for all you're help HJB, I appreciate it very much! The last question I have is, that when I run the server everythign is fine, then when a user connects it instantly jumps to 99% processor usage and slows my whole system down. Any idea why?
-
But will that allow him to get Firefox's and opera's urls?
-
Which browser are you trying to get the URL's from? Also, for instance using IE, do you need the history of urls for that instance of IE or just the current one in the open IE windows? I am new to .NET so I am not sure about the namespaces to do that. I rely on API. What I would do, is make a enumerator and go through all the current open windows. Find all the windows with classname cls_Name where cls_Name could be the classname of IE,Netscape,Opera,Firefox, etc. Then find the combobox which holds the url and finally a sendmessage to tranfer the data. I am sure there is an easier more reliable and proficient way, but again I am not used to .NET
-
HJB, I do appreciate all the time and posts you made! ;) Screenshot - Click Here Server Code: [CS] private void SomeoneConnected(IAsyncResult result) { //result.AsyncState stores the 2nd argument of BeginAccept //in this case, a socket, because I made it store a socket. Socket socket = (Socket) result.AsyncState; //you need to call end accept to get the connected socket. Socket remoteEnd = socket.EndAccept(result); t1.Text += "\r\nSomeone Connected!"; //call begin accept again to get the next incoming connection. byte[] buffer = System.Text.Encoding.UTF8.GetBytes(""); remoteEnd.BeginReceive(buffer,0,buffer.Length,System.Net.Sockets.SocketFlags.None,new AsyncCallback(CheckPackets),remoteEnd); socket.BeginAccept(new AsyncCallback(SomeoneConnected), socket); } private void CheckPackets(IAsyncResult result) { //byte[] buffer = System.Text.Encoding.UTF8.GetBytes("no"); Socket socket = (Socket) result.AsyncState; int dsocket = socket.EndReceive(result); if (dsocket<=0) { } else { t1.Text+="\r\nReceived " + dsocket + " bytes of data." + " - " + System.Text.Encoding.UTF8.GetString(buffer); } socket.BeginReceive(buffer,0,buffer.Length,System.Net.Sockets.SocketFlags.None, new AsyncCallback(CheckPackets),socket); } [/CS] Client code: [CS] /********************/ byte[] msg = System.Text.Encoding.UTF8.GetBytes("Test message!"); public Socket mysocket; /********************/ private void Connected(IAsyncResult result) { //result.AsyncState stores the 2nd argument of BeginAccept //in this case, a socket, because I made it store a socket. Socket socket = (Socket) result.AsyncState; //you need to call end accept to get the connected socket. socket.EndConnect(result); mysocket = socket; label1.Text += "\r\nWe Connected!"; sendstuff(mysocket); } private void button2_Click(object sender, System.EventArgs e) { sendtuff(mysocket); } private void sendstuff(Socket socket) { socket.BeginSend(msg,0,msg.Length,System.Net.Sockets.SocketFlags.None,new AsyncCallback(sending),socket); } private void sending(IAsyncResult ar) { Socket socket = (Socket) ar.AsyncState; int i = socket.EndSend(ar); Console.WriteLine("Sent " + i + " Bytes."); } [/CS]
-
Anyone have an idea?
-
What exactly are you trying to do?
-
Ok, I can send data between the two programs, but it only sends it 1 byte at a time... Is there any way to send it all at once?
-
Still confuzzled Ok Hjb, I attempted for two days now to get the receive and send to work, no such luck (I must be brain dead). In the server portion I have this: [CS] private void SomeoneConnected(IAsyncResult result) { //result.AsyncState stores the 2nd argument of BeginAccept //in this case, a socket, because I made it store a socket. Socket socket = (Socket) result.AsyncState; //you need to call end accept to get the connected socket. Socket remoteEnd = socket.EndAccept(result); t1.Text += "\r\nSomeone Connected!"; //call begin accept again to get the next incoming connection. byte[] buffer = System.Text.Encoding.UTF8.GetBytes(""); socket.BeginReceive(buffer,0,buffer.Length,System.Net.Sockets.SocketFlags.None,new AsyncCallback(CheckPackets),socket); socket.BeginAccept(new AsyncCallback(SomeoneConnected), socket); } private void CheckPackets(IAsyncResult result) { byte[] buffer = System.Text.Encoding.UTF8.GetBytes(""); Socket socket = (Socket) result.AsyncState; int dsocket = socket.EndReceive(result); socket.Receive(buffer); t1.Text+="\r\n" + System.Text.Encoding.UTF8.GetString(buffer); socket.BeginReceive(buffer,0,buffer.Length,System.Net.Sockets.SocketFlags.None, new AsyncCallback(CheckPackets),socket); } [/CS] In the client part I have: [CS] private void Connected(IAsyncResult result) { //result.AsyncState stores the 2nd argument of BeginAccept //in this case, a socket, because I made it store a socket. Socket socket = (Socket) result.AsyncState; //you need to call end accept to get the connected socket. socket.EndConnect(result); label1.Text += "\r\nWe Connected!"; byte[] msg = System.Text.Encoding.UTF8.GetBytes("Test message!"); int i = socket.Send(msg); Console.WriteLine("Sent " + i + " bytes of data."); } [/CS] The client responds as sending 13 bytes of data, but in the server program I receive the error: An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll Additional information: AcceptCallback What am I doing wrong?!
-
There are a few different methods, I believe this will help Sorting Methods. Just make sure when you use them instead of using array use array[0] so that you know to use the first integer in the ith array.
-
Thanks HJB, the way you explained it was, well, the best i've seen! I am starting to understand it now. So basically I am going to have to do the same thing for reading and writing data... I would have to make all of those using the same argument list so that they would be asynchronous...
-
HJB, the examples I looked at are poorly commented. If you could make a small example of the asynchronous or have an example that is commented well handy I would greatly appreciate it :D
-
I am just having the hardest time understanding it. The easiest way I found was the way I posted above. I just don't really get teh asycnhronous part. For example, you have to have a delegate? Ugh, it's going to be a long night.
-
Hello everyone, I am attempting to make a client/server program using sockets, but the program hangs on the Socket.AcceptConnection() line until there is a connection made. I was searching around and found some code on how to do it, but it used neither the AcceptConnection using a listener nor the read.ReadString(). I was wondering if anyone knows of some good tutorials or has some commented socket code laying around. MSDN was a waste of time, since I am new to network programming. I want to have multiple clients connected to the server at one time, and be able to send information back and forth. Not looking for many clients, max will probably be 50, if that. I was using the following code: [CS] private void wfc() { TcpListener listener; try { while(true) { listener = new TcpListener(50000); listener.Start(); connection = listener.AcceptSocket(); clsClient CC = new clsClient(connection, this.t1); listener.Stop(); listener = null; } } catch(Exception e) { t1.Text = e.ToString(); } } [/CS] Thanks, -Cold
-
Nevermind, somehow it fixed itself after a restart... :confused:
-
I am trying to make an asp page talk to a program on another computer, when I attempt to connect to it from the webpage I get: System.Net.Sockets.SocketException: The requested name is valid, but no data of the requested type was found at System.Net.Dns.GetHostByName(String hostName) at System.Net.Dns.Resolve(String hostName) at System.Net.Sockets.TcpClient.Connect(String hostname, Int32 port) any ideas guys?