It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Multithread Chat server side crash

Moderator: dafunkymunky

Multithread Chat server side crash

Postby Bartude on Wed May 18, 2011 10:40 am

Hey, i'm doing a chat for a project, and it works like this. The server connects, the clients connect, one client sends a message to the server, and the server broadcasts it to the other clients. But what I want to do now is to also have the server communicate with the clients. But when I click on the server form, it freezes, and I cant do nothing.

I think this is because of me not creating a thread for the communication(I saw this on another forum), but I dont know how to do that. I copied basically all the chat program code from a site, and I dont know much of sockets and what not.

If anybody knows how to fix this, it would be awesome :D

Thanks
Bartude
 
Posts: 1
Joined: Wed May 18, 2011 10:36 am

Re: Multithread Chat server side crash

Postby sanjon on Mon Jun 06, 2011 3:14 pm

I'm new to this as well, but I'll try my best to help.

First of all, you should create a sub that contains the code that the thread should execute. Then you create the thread and make it run through the sub whenever you want it to start. In my example I started the thread when the from loads. Here is the example:

Code: Select all
Sub Listen()
'Type the code that should be executed here.
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        listenthread = New System.Threading.Thread(AddressOf Listen)
        listenthread.Start()
End Sub


When you create the thread, all you need is the name of the sub you want it to use. In this case it is "Listen". I hope this helps.
sanjon
 
Posts: 40
Joined: Sun Dec 05, 2010 6:20 pm


Who is online

Users browsing this forum: No registered users and 2 guests