CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

TCP server
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sat Feb 12, 2011 4:40 am     Reply with quote

Back to the original problem...

I found that when the transfer hangs through the internet, the "TCPIsConnected(socket)" returns true, so I am still connected to the remote PC but "TCPIsPutReady(socket)" returns false after some time, so, my data is not sent out.

Now, when the remote PC sends me a byte of data, the PIC will continue to send out my data and "TCPIsPutReady(socket)" returns true.

Let's say that the PIC is not TCPIsPutReady. What can I do to make it ready again? Should I just wait?
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Feb 12, 2011 10:26 pm     Reply with quote

Well, I've not had any trouble on any ports. Maybe you have an antivirus or firewall blocking things?
_________________
Andrew
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Feb 12, 2011 10:32 pm     Reply with quote

Re: TCPIsPutReady(), you are calling TCPFlush() when you want the data to go?
_________________
Andrew
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sun Feb 13, 2011 2:52 am     Reply with quote

This is what I call for sending out the data:

Code:

int trans(){

    if(TCPIsPutReady(c_socket)) {
     TCPPut(c_socket,buffer[0]); 
     TCPPut(c_socket,buffer[1]); 
     TCPPut(c_socket,buffer[2]); 
     TCPPut(c_socket,buffer[3]); 
     TCPPut(c_socket,buffer[4]); 
     TCPFlush(c_socket);
     led_err=0;
     buzzer=0;
     return 1;
   }
   else{
    printf("\n\rNot PUT ready.");
    led_err=1;
    buzzer=1;
    return 0;
   }
}


I use the above to send 5 bytes to the PC but after a while it hangs when used through the internet.
Yesterday I found that if my PC side VB app. sends one dummy byte to the PIC every 300mS, the transfer does not hang. Maybe it needs both ends to talk to each other. Also I saw in wireshark that I have some duplicate acks when it hangs.

It should not be a firewall problem because if it was then it would not wotk at all. right?

Keep in mind that everything works perfectly in my LAN for many hours.

Finally what is the best way to send/receive data reliably though the internet?

UDP did not work at all even though I see (in wireshark) that the PIC sends the data, but I cannot receive it in any way.
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sun Feb 13, 2011 11:19 am     Reply with quote

That looks fine to me, but I can't explain what happens when it gets stuck over the Internet.

For really long duration comms, I'd still recommend UDP.
_________________
Andrew
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sun Feb 13, 2011 1:03 pm     Reply with quote

Andrew,

UDP finally works! the problem was that avast internet security was blocking all UDP packets even though it was disabled. Now it is uninstalled and everything is OK ;)

So, I am back at the CCS UDP example.

I have it working!
Just a question, should I always open a socket, send out my packet and then close it every time or I just open it once and send out all data for one session? The same question for receiving.

Thanks
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sun Feb 13, 2011 10:19 pm     Reply with quote

Good to hear you sorted your UDP problem.

Re: Opening/closing: It depends Smile

For receiving I keep a socket open all the time and typically send replies back on the same.

For unsolicited sending I open and close a new socket, like in the ntp_sendreq and test_send_udp functions in the earlier posts.
_________________
Andrew
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu Feb 17, 2011 4:53 pm     Reply with quote

Andrew,

UDP is working perfectly without problems.

Thank you so much for the help!

George..
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Feb 17, 2011 8:57 pm     Reply with quote

That's great! Have you been able to restore Avast and keep the UDP packets?
_________________
Andrew
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 12:28 am     Reply with quote

No, Avast is gone! It was too heavy anyway...
Do you know how many bytes I can send with one flush? What is the size of the transmit buffer?
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 18, 2011 1:28 am     Reply with quote

georpo wrote:
No, Avast is gone! It was too heavy anyway...

Well I hope you've got some sort of firewall in place...
Quote:
Do you know how many bytes I can send with one flush? What is the size of the transmit buffer?

It will be #defined in the code somewhere, but I'd say at least 1KB, possibly 1.5KB. It might even be variable! Use UDPIsPutReady() to check.
_________________
Andrew
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 2:41 pm     Reply with quote

Ok, thanks!!!

if you want check this:

http://georpo.dyndns.org

It is my custom PIC board that I use for TCP/UDP practice Smile


George.
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Feb 19, 2011 1:25 am     Reply with quote

That's a nice looking case. I bet the LCD display is handy for debugging! Here's my NTP server:

http://www.scss.com.au/family/andrew/gps/ntp/

It can be a bit challenging debugging with just a couple of LEDs, but I got there Smile
_________________
Andrew
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sat Feb 19, 2011 5:39 am     Reply with quote

haha, my project is like a toy compared to yours.

Very nice job Andrew!

After I finish the tests I will make a pcb with green solder mask. It looks much better. Mine is a sample, it is not even plated through...
I will also change the power supply and use a 34063 because the 7805 gets hot and needs a cooler which makes the device look bad.

I made the front and back panels of FR4 1mm. It is much easier to make holes than in aluminium...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group