|
I want a simple socket programming application in vb.net. Can any one of them help me out.
|
|
|
|
|
This might help u out..
http://www.eggheadcafe.com/articles/20020323.asp
http://www.developerfusion.com/show/1845/
|
|
|
|
|
Sorry, but I'm too lazy to copy and paste that in to the browser....
http://www.eggheadcafe.com/articles/20020323.asp[^]
http://www.developerfusion.com/show/1845/[^]
That's better!
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
Is there such a thing as a copy constructor in VB.NET?
How do I copy a class? Do I have to copy the class data explicitly?
Thanks in advance
JP
Rugby League: The Greatest Game Of All.
|
|
|
|
|
PaleyX wrote:
How do I copy a class?
Yes, if the class supports the ICloneable interface, you can use the <object>.Clone() method to create a copy of the object. SUch as copying a Bitmap object:
Dim cloneBitmap As Bitmap = myBitmap.Clone(cloneRect, format)
RageInTheMachine9532
|
|
|
|
|
I have just written my first VB.Net application. It uses a custom control, which I put into a control library project, which is loaded from a subroutine. the application runs fine when I build it in .Net, but when I use a startup project to build an installer,then install the application and try to launce the application, I get an error that the custom control or one of its dependencies can't be found. I traced the dependency that is not being found to the mscorlib. The application and teh custom control both have the following references:
Interop.Excel (10)
Microsoft.Office.Core
stdole
System
system.Data
System.Drawing
System.Windows.Forms
System.XML
Interop.VBIDE
1) How can I correct the dependency not found problem? I read that "you should avoid loading assemblies at run time by means of code or manually add the dependent assemblies to your deployment project". How do I add the assembleis (and which ones) to the deployment project?
2) What is the Interop VBIDE?
2) How do I deal with the dependencies on Office and Excel object libraries in my deployment. I found a help file that says to exclude the dependencies on other products from the deployment project, and write launch condition to prevent installation if the dependent file is not found. How do I do that?
Please respond quickly, I am supposed to send this application out for testing this week!
Thanks!
|
|
|
|
|
Have you installed the .Net Framework on the target machine?
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
LearnVisualStudio.Net
|
|
|
|
|
I am attempting to write an image to a network stream and am experiencing dificulties.
I have tried something allong the lines of:
<br />
myImage.Save(myNetworkStream, System.Drawing.Imaging.ImageFormat.Bmp)<br />
This causes a exception:
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll
Additional information: A generic error occurred in GDI+.
So I changed my code to:
<br />
Dim ms As New System.IO.MemoryStream()<br />
'' write the image to the memory stream<br />
myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)<br />
'' declare a byte array <br />
Dim b(ms.Length - 1) As Byte<br />
'' set the position within the memory stream<br />
ms.Position = 0<br />
'' read the memory stream into byte array<br />
ms.Read(b, 0, ms.Length)<br />
'' write the byte array into the network stream<br />
myNetworkStream.Write(b, 0, b.Length)<br />
Is there a better way? Can anyone see why the first method threw an exception?
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
LearnVisualStudio.Net
|
|
|
|
|
i have just purchased and installed (successfully the message said) visual basic.net standard 2003. I am unable to create a new project, add a new item or blank solution. In fact, anything to do with adding or new windows form it will generate an error saying it cannot perform this operation. Can anyone help, with this problem.
|
|
|
|
|
Supplying the EXACT error message would very much help to determine the problem.
RageInTheMachine9532
|
|
|
|
|
When creating XML is better to just use string concatenation or use the XML document and create it in that? How would I go about doing the second?
Thanks
Jon
Rugby League: The Greatest Game Of All.
|
|
|
|
|
It seems to me that there are 1000s of examples of how to read XML but very few on how to write XML - I have always used string concatenation but it can look a bit messy after a while.
Rugby League: The Greatest Game Of All.
|
|
|
|
|
anyone can provide coding to print out the content of picturebox and richtext box using print dialog??any help is greatly appreciated... VB.NET
|
|
|
|
|
There is an interesting article called
Getting WYSIWYG Print Results from a .NET RichTextBox
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/wnf_RichTextBox.asp
It can be of great help.
Good work.
Bye.
|
|
|
|
|
Hello,
I am receiving data of 3 KB from a Linux Server in a VB client which connects to the server after every 2 minutes(using a timer).I am working in a LAN. I dump the data received in a text box after the .GetData method.The problem is that at an average of 40% of the time I am getting no/garbage data.The pattern is inconsistent i.e.it might receive correct data 5 times and then maybe fail 2 times.
Can anybody suggest a reason for this because I think I should receive data with more than 90% success in a small network.
Also,is it possible to assign more than 1 port in a server and and have the client connect to the different ports ? If yes, how ? I want to know this because I want to send/receive different data through different ports for different screens in the VB client application.
Thanks,
Dhrubo
Dhrubo
|
|
|
|
|
You might want to include some code samples from the server and client so we can see what your doing right/wrong.
RageInTheMachine9532
|
|
|
|
|
As requested by Dave Kreskowiak, I am including the code for the client and server so that somebody can suggest a solution.
Thanks for any help in advance.
Server:
void main(void)
{
create_socket();
bind_socket();
listen_client();
while(1)
{
connect_client();
send_data(); //receive_data();
shutdown(newSockfd,0);
close(newSockfd);
} /* Outer While closed */
return 0;
} /* end main */
void create_socket()
{
sockfd = socket(PF_INET,SOCK_STREAM,0);
if( sockfd < 0 )
{
printf("\nsocket can not be created !!!!");
return;
}
printf("\nsocket created,");
printf(" my descriptor:- %d",sockfd);
}
void bind_socket()
{
int ret_stat;
memset((char*) &servAddr,'\0', sizeof(servAddr));
servAddr.sin_family = PF_INET;
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
//servAddr.sin_port = htons(nTCPPort);//
servAddr.sin_port = htons(PORT_NO);
printf("\n Server Port Number = %d",servAddr.sin_port);
ret_stat = bind(sockfd, (struct sockaddr *)&servAddr,sizeof(servAddr));
if(ret_stat < 0)
{
printf("\nBind Error Status:%d",ret_stat);
exit(0);
}
printf("\nBind Success Status:%d",ret_stat);
return;
}
void listen_client ()
{
ret_stat = listen(sockfd,5);
if(ret_stat < 0)
{
printf("\nListen Error Status:%d",ret_stat);
exit(0);
}
printf("\nListen Success Status:%d",ret_stat);
return;
}
void connect_client(void)
{
printf("\nWaiting For Client To Connect : ");
len = sizeof(struct sockaddr);
newSockfd = accept(sockfd, (struct sockaddr *)&from, &len);
if(newSockfd < 0)
{
printf("\n accept request failed ");
}
printf("\n Client Connected ");
}
void send_data(void)
{
int send_stat;
int i,k=0;
char temp[12],buff[3000];
double decr_temp1 = 0.00,decr_temp2 = 0.00,decr_temp3 = 0.00,decr_temp4=0.00
float decr_temp5 = 0.00, decr_temp6 = 0.00;
int decr_temp7 = 0, decr_temp8 = 0;
short int decr_temp9 = 0,decr_temp10 = 0;
long int slab_no = 54790000;
//char temp1;
for (k=0;k<40;k++)
{
slab_no = slab_no + 1;
sprintf(slabdata[k].slabid,"%ld,",slab_no);
//0.--------------------------------------
if (k==0) strcpy(buff,slabdata[k].slabid);
else strcat(buff,slabdata[k].slabid);
// 1.---------------------------------------
slabdata[k].slabtemp = 900.00 - decr_temp1;
sprintf(temp,"%.2lf,",slabdata[k].slabtemp);
strcat(buff,temp);
decr_temp1 = decr_temp1 + 25.00;
//2.------------------------------------------------
slabdata[k].uptemp = 800.00 - decr_temp2;
sprintf(temp,"%.2lf,",slabdata[k].uptemp);
strcat(buff,temp);
.
.
. // for another 8 sets of data for total 10
}
send_stat = send(newSockfd,buff,sizeof(buff),0);
if (send_stat<0) //newly added
{
printf("\n Sending Error status :%d",send_stat);
exit(0);
}
printf("\n The length of Data that was sent is %d ",strlen(buff));
}
Client:
I am using the timer2 and the labels for testing the output and the will remove them later.
As a test, before the data arrival event I am disabling the timer and after the data has been received I enable ii because I thought the timer's priority was causing a problem.
-------
Dim mydata As String
Private Sub Form_Load()
Label8.Caption = Time
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Time
If DateDiff("n", Format(TimeValue(Label8.Caption), "hh:mm:ss"), Format (Time, "hh:mm:ss")) >= 2 Then
Label8.Caption = Time
If Command1.Enabled = False Then Command1.Enabled = True
Command1_Click
End If
End Sub
Private Sub Command1_Click()
a = ""
If Winsock1.State <> sckClosed Then Winsock1.Close
Command1.Enabled = False
Timer1.Enabled = False
Winsock1.Connect "151.0.22.60",7500
End Sub
Private Sub Winsock1_Connect()
Timer1.Enabled = False
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim I As Integer
Static bkupbuff As String
Static counter As Integer
Label6.Caption = "Bytes Received : " & Winsock1.BytesReceived & " Bytes Total parameter : " & bytesTotal
On Error Resume Next
Winsock1.GetData a, vbString
Label4.Caption = "Length of a : " & Len(a)
If Len(a) < 2675 Then
Text1.Text = a
a1 = bkupbuff
Label9.Caption = "FAILED " & Len(Trim(Text1.Text))
a = ""
Else
Text1.Text = a
a1 = a 'for array purposes
bkupbuff = a 'for back up during error in data receive
a = ""
Label9.Caption = "SUCCESS " & Len(Trim(Text1.Text))
End If
Label5.Caption = Label5.Caption & " " & Str(counter): counter = counter + 1
Timer1.Enabled = True
Label8.Caption = Time
If Command2.Enabled = False Then Command2.Enabled = True
End Sub
Private Sub Timer2_Timer()
Label3.Caption = Time
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, _
ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error in socket : " + Description, vbOKOnly
End Sub
|
|
|
|
|
For the code below, I always get an empty string from "GetWindowText()" call, instead of getting the caption or title of the window.
Not sure, why am I getting that empty string?
Any help is appreciated.
Thanks.
===========================================
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessIDs(0))
If hProcess <> 0 Then
lRet = EnumProcessModules(hProcess, Modules(1), 200, cbNeeded2)
If cbNeeded2 > 500 Then
cbNeeded2 = 500
End If
If lRet <> 0 Then
For j = 1 To cbNeeded2
ModuleName = Space(MAX_PATH)
nSize = 500
x = GetWindowTextLength(hProcess)
str = Space$(x)
x = GetWindowText(hProcess, str, x)
tl_dt_GetPID = ProcessIDs(0)
lRet = CloseHandle(hProcess)
Exit Function
Next j
End If
End If
lRet = CloseHandle(hProcess)
End Function
|
|
|
|
|
See my reply in the other thread...
RageInTheMachine9532
|
|
|
|
|
I am attempting to stong name my first assembly. I found the Sn.exe utility,but can't seem to open it. When I try, it flashes on the screen and then disappears. The reference book I am using is very vague on how to use the utility. what am I doing wrong?
Please respond as soon as you can, I need to get the deployment done so I can get this application to my associates!
Thanks!
|
|
|
|
|
That's because SN is a command line utility. It doesn't have a window interface. Go to Start/Programs/Microsoft Visual Studio .NET (2002|2003)/Visual Studio .NET Tools and click on Visual Studio .NET (2002|2003) Command Prompt. Then type your SN command in there.
RageInTheMachine9532
|
|
|
|
|
Thanks!
Now I have another problem. My application references both Interop.Excel and Interop.VBIDE. after I assigned a strongname key pair to the (2) assemblies I wrote, I tried to build the solution, and got a build error saying that I needed to strong name these two assemblies. How do I do this?
Thanks Again!
|
|
|
|
|
Hi,
From VB, how can we kill a particular process, given the following scenario:
I see 2 applications, say cmd.exe in task manager and only one of them is of my concern, which I would like to kill from VB.
How can I distinguish this cmd.exe from the other. Note that I dont know which one to kill just by looking at it and also the process ID's change everytime I restart an application which generates this cmd.exe
Any help is appreciated.
Thanks.
|
|
|
|
|
In simple terms, you can't tell them apart unless there is a property that is unique to the process your trying to kill, like MAYBE its MainWindowTitle.
Use the Process class to get the list of processes. You can then use the Close method on the instance of Process to terminate that process.
RageInTheMachine9532
|
|
|
|
|
OK thanks,
The process cmd.exe is generated from VC++.
So I added the title bar from VC++ using
STARTUPINFO.lpTitle = "foo";
And from VB I used GetWindowText(), but it always gives back an empty string instead of the title(foo) of that process (cmd.exe).
I have defined GetWindowText() in VB as:
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Any clue why am I getting empty string back and not the title?
|
|
|
|
|