Click here to Skip to main content
16,009,068 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: vb net Pin
Dave Kreskowiak4-Apr-04 17:52
mveDave Kreskowiak4-Apr-04 17:52 
GeneralXML and VB.NET Pin
PaleyX3-Apr-04 10:35
PaleyX3-Apr-04 10:35 
GeneralRe: XML and VB.NET Pin
PaleyX4-Apr-04 3:07
PaleyX4-Apr-04 3:07 
Questionhow to print out the content of picturebox and richtexbox using print dialog? Pin
MJay3-Apr-04 3:02
MJay3-Apr-04 3:02 
AnswerRe: how to print out the content of picturebox and richtexbox using print dialog? Pin
Ricci Gian Maria4-Apr-04 21:19
Ricci Gian Maria4-Apr-04 21:19 
GeneralData load for Winsock Client Pin
DhruboMitra2-Apr-04 19:43
DhruboMitra2-Apr-04 19:43 
GeneralRe: Data load for Winsock Client Pin
Dave Kreskowiak3-Apr-04 2:05
mveDave Kreskowiak3-Apr-04 2:05 
GeneralRe: Data load for Winsock Client Pin
DhruboMitra8-Apr-04 18:09
DhruboMitra8-Apr-04 18:09 
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
GeneralProblem with GetWindowText() in VB Pin
ndalal2-Apr-04 9:12
ndalal2-Apr-04 9:12 
GeneralRe: Problem with GetWindowText() in VB Pin
Dave Kreskowiak2-Apr-04 10:01
mveDave Kreskowiak2-Apr-04 10:01 
GeneralStrong Naming Pin
nvmoss2-Apr-04 6:09
nvmoss2-Apr-04 6:09 
GeneralRe: Strong Naming Pin
Dave Kreskowiak2-Apr-04 6:21
mveDave Kreskowiak2-Apr-04 6:21 
GeneralRe: Strong Naming Pin
nvmoss3-Apr-04 7:26
nvmoss3-Apr-04 7:26 
QuestionHow to Kill a particular process Pin
ndalal2-Apr-04 5:14
ndalal2-Apr-04 5:14 
AnswerRe: How to Kill a particular process Pin
Dave Kreskowiak2-Apr-04 6:03
mveDave Kreskowiak2-Apr-04 6:03 
GeneralRe: How to Kill a particular process Pin
ndalal2-Apr-04 7:10
ndalal2-Apr-04 7:10 
GeneralRe: How to Kill a particular process Pin
Dave Kreskowiak2-Apr-04 7:29
mveDave Kreskowiak2-Apr-04 7:29 
GeneralRe: How to Kill a particular process Pin
ndalal2-Apr-04 7:33
ndalal2-Apr-04 7:33 
GeneralRe: How to Kill a particular process Pin
Dave Kreskowiak2-Apr-04 9:59
mveDave Kreskowiak2-Apr-04 9:59 
GeneralHi everyone.. I need help about Crystal Reports Pin
jlizardo2-Apr-04 4:14
jlizardo2-Apr-04 4:14 
GeneralRe: Hi everyone.. I need help about Crystal Reports Pin
Wayne Phipps2-Apr-04 22:00
Wayne Phipps2-Apr-04 22:00 
GeneralDialogResult problem Pin
El'Cachubrey2-Apr-04 3:10
El'Cachubrey2-Apr-04 3:10 
GeneralRe: DialogResult problem Pin
Dave Kreskowiak2-Apr-04 3:21
mveDave Kreskowiak2-Apr-04 3:21 
QuestionHow to Start a Program as an Application from a Windows Service Pin
SalilSawant2-Apr-04 1:47
SalilSawant2-Apr-04 1:47 
AnswerRe: How to Start a Program as an Application from a Windows Service Pin
Dave Kreskowiak2-Apr-04 3:09
mveDave Kreskowiak2-Apr-04 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.